![]() |
Simple True False Searches![]() ![]() ![]() ![]() ![]()
The m//operator, which returns true or false depending on whether it finds what it is searching for. It's very handy when you're learning regular expressions because you can write tiny programs to test strings. The m operator is followed by the regular expression that you want to test. Because most people use the slash V) character at the beginning and end of their regular expressions, many people call the m operator the m H operator instead. The m// operator tests this against something that is given to its left, preceded by the =~operator. If you use the slash character you don't have to include m. For example, to test whether the string "abc#clef" contains the string #, you could use if ("abc#def" =~m /#/) { print "True\n"; } else { print "False\n"; Of course, running this string prints True on your screen.
You can, of course, also use variables on the left side of the = operator: ( print "True\ n" ;) else ( print "Flase\n" I You may also want to generate a true value if the pattern is not found. For this task, use the ! ~ operator instead of the = ~ operator if Vest ! m/#/) If there is, no hash character ... You can use variables in your search. For example, if $find contains the string you want to search for and $Test is the string you want to search in, you would use if ($Test =~ m/$find/) And, to get things even more compact, if you are searching in Perl's special variable $_, you don't need the the = at all. Remember That the file input operator <> puts the next line of the file into $_. Thus you may see soemthing like this:
while (
|
|
PERL Perl Program Data Types Types of Variables Operator Types Functions String Functions Array Functions Expressions Statement Blocks The if Statement Unless Statement While Loops Until Loop For Loop Foreach Loop Jump Keywords Subroutines Perl References Die Function Exit Function Localtime Function Standard Files File Test Operators File Functions Opening Files Reading into Hash Printing Revisited Globbing Splitting a Record into Fields Perl's Special Variables Regular Expression Simple True-False Searches Inexact Matches in Regular Expressions Matching Any Character Characters with Class Special Locations Quantifiers Greedy Matching Modifiers Localtime Function Subsituations Letter for Letter Translations Generating A Simple Report Defining a Report Template Specifying the Picture Line Specifying the Argument Line Adding a Header Writing the ReportDomain Names Home Importance of a domain name How does a web domain name work? Domain name syntax Choosing a domain name Domain Transfer Domain Parking IP AddressWeb Design HTML DHTML XML JAVASCRIPT VBSCRIPT PHOTOSHOPWeb Hosting Web Server Web Server Software Microsoft Internet Information Server Web hosting ISP Shared web hosting Virtual web hosting Dedicated web hosting Web hosting colocation Managed web hostingE Commerce Principles of E-Commerce E-Banking Electronic Payment System E-Security Credit Cards Smart Cards
The Mailbox POP Server SMTP Server IMAP Protocol |
| Home | Web Hosting | Web Design | Sitemap |
| Copyright (C) 2007. Web Domain design hosting. All rights reserved. |