Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

m modifier

by abubacker (Pilgrim)
on Aug 14, 2009 at 05:42 UTC ( #788519=perlquestion: print w/replies, xml ) Need Help??

abubacker has asked for the wisdom of the Perl Monks concerning the following question:

Dear all,
Can any one explain me about "m" and "s" modifier with an example
I referred perlretut but I was not able to understand that
Please help me out

Replies are listed 'Best First'.
Re: m modifier
by ELISHEVA (Prior) on Aug 14, 2009 at 06:02 UTC

    A vast improvement over your last question! (saying what you tried)

    You are right - perlretut only tells you that there is an m modifier. It doesn't really explain it. For an explanation, look at perlre

    Best, beth

Re: m modifier
by hnd (Scribe) on Aug 14, 2009 at 06:13 UTC
    i had this doubt before and got it cleared here.... this is what i learned....

    /m modifier are used to to let $ and ^ match before and after a \n respectively for eg if you do  /^foo/m it would not only match at the beginning but also right after a newline character (ie the second line)...

    now for /s modifier it is necessary to know what '.' does usually. it doesn't match the newlines normally ie you have to force it to match the newlines as well for eg  / would match foo and bar on different lines...

    i'am worst at what do best and for this gift i fell blessed...
    i found it hard it's hard to find well whatever
Re: m modifier
by perldesire (Scribe) on Aug 14, 2009 at 12:40 UTC

    m modifier treats the string as a set of multi line. In your regular expression "." (dot) matches a character other than \n (newline), because it treats the string as a multiline.

    s modifier is very simple, it takes the whole string (doesnt care about how many \n), and consider as a single long string.

    my $string; $string="PERL is an Acronym of practical extraction and report languag +e\ni like it very much"; # here "." is as usual i.e any single character.(including \n) so it m +atches and returns 1. print $string =~ /language.i/s; # here "." matches any character other than \n, but in our string lang +uage followed by \n is there. so it doesnt return 1. its false. print $string =~ /language.i/m; # here \n followed by i will match so returns true. print $string =~ /language\ni/m; # As simple s modifier consider . as a single character. that could be + anything... returns true... print $string =~ /language\ni/s;

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://788519]
Approved by ELISHEVA
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2022-05-17 04:19 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (65 votes). Check out past polls.