Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

m modifier not doing what I'm expecting?

by ultranerds (Friar)
on Dec 21, 2011 at 12:09 UTC ( #944601=perlquestion: print w/replies, xml ) Need Help??
ultranerds has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm trying to work out why this regex isn't working as I'm expecting. I'm using the /m modifier to make it treat the data as "new lines" per row, but it seems to just keep looping through on the first one:
my $data = <<_DATA_; == Example header 1 == a f == Header 2 example ==== sub header a sub sub header :) == Testing header item with some stuff in [[fffsdfsdf]] _DATA_ while ($data =~ /^\=\= (.+?)$/m) { print "FOO: $1 \n"; }
..just keeps printing out:

FOO: Example header 1 (repeatedly, til you kill the script)

Can anyone point me to where I'm going wrong?

TIA!

Andy

Replies are listed 'Best First'.
Re: m modifier not doing what I'm expecting?
by Eliya (Vicar) on Dec 21, 2011 at 12:15 UTC

    You also want the /g modifier.  (/m alone matches from the beginning every time, thus the endless loop...)

      Aaah thanks - so was just missing the /g ... works like a charm now. Thanks!

      Andy
Re: m modifier not doing what I'm expecting?
by moritz (Cardinal) on Dec 21, 2011 at 12:14 UTC

      This is not a problem here, as the dot isn't supposed to match a newline.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://944601]
Approved by Corion
help
Chatterbox?
[Corion]: Their older sister just started piano but has been interested in drumming, which she should be able to start with 8 years or so)
[Discipulus]: ah was Kink of Bongo 1992..
[1nickt]: choroba name of band? youtube link? MySpace link?
[Your Mother]: I like Manu Chao.
[Your Mother]: I like this one quite well, https://www. youtube.com/watch? v=rSEUH4KRfN8
[choroba]: Půlnoční Marie (which means Midnight Mary)
[choroba]: but the band is practically dead. We rehearse once in a year, and perform with the same frequency
[ambrus]: `quote
[ambrus]: sorry, typed in the wrong box
[LanX]: Your mother: je ne t'aime plus! ;)

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2017-03-24 12:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (301 votes). Check out past polls.