Modifiers

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

The m // operator has modifiers that change the way m// works to search. The modifiers come after the closing slash character, such as the i modifier in the following: if ($Test =~ =~ (N.*T)/i)

g - Returns each occurrence (global search)
i - Ignores case
m - Allows multiple lines in the string
o - Compiles the pattern once (rarely used)
s - Treats as a single line
x - Allows whitespace for comments
the m,s, and x modifiers are new in Perl 5. The i option simply forces Perl to ignore case when searching.

For example, if $Test is "nest",
if($Test =~ /(N.*T)/i)
would be true.

Global Searches in the m// Operator

The g modifier causes Perl to do a "global" search on the string. This may at first sound odd, because Perl is supposedly already searching the whole string. The global here refers to the way that Perl returns different results based on the g modifier.

In a list context, Perl returns a list of the strings matched using parentheses. However, if the regular expression contains no parentheses, Perl creates a list of each matched item:

$Test = 'NESTING';
@Birds = ($Test =- /N./g);
print join ("\n", @Birds);
When you run this program, Perl displays
NE
NG
This is a handy way to find all the matching strings if you don't know how many there will be.



Domain Name Search

www.


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