Simple True False Searches

Domain Hosting image
Web Hosting
Dedicated server
ssl certificate
Web Design image
Email

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:
if ($Test =~ m/#/)

( 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 () {


if (/Proprietary/) ( #The line has the keyword



Domain Name Search

www.


Copyright (C) 2007. Web Domain design hosting. All rights reserved.