Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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

by ed (Initiate)
on Apr 07, 2015 at 15:49 UTC ( #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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1122713]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2018-07-21 04:19 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (444 votes). Check out past polls.