Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Perl Idioms Explained - @ary = $str =~ m/(stuff)/g

by ed (Initiate)
on Apr 07, 2015 at 15:49 UTC ( [id://1122713]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl Idioms Explained - @ary = $str =~ m/(stuff)/g
in thread Perl Idioms Explained - @ary = $str =~ m/(stuff)/g

I am the author of the above comment. Something like this seems to work:
$result =~ /\A/g or die; # make extra sure we are at start of string @r = ($result =~ m/\G(foo)/gc); if ($result =~ /\G(.+)/sg) { warn "leftover junk at the end of result: $1"; }
The key is the /c flag on the repeated match so that when it fails, it leaves the match position in place so the trailing junk, if any, can be reported. If there is leading junk, then the regexp won't match any times, and the whole string will be reported as 'leftover'. That is a good enough error message for my purposes.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1122713]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-03-29 07:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found