It is a pretty crappy example but what it does is include some code in the match regex which gets executed. Basically we try for a match with (pseudocode)m/.{0,length $_}lori/ and use $i to remember how many chars we needed to eat up to find "lori". There are far easier ways to do this like using pos() and a positive lookahead assertion if you want a regex solution or just plain old index():
$_ = "lothlorien"; m/ (?{ $i = 0 }) (. (?{local $i = $i + 1; }) )* lori (?{ $result = $i }) /xi; print "\$result=$result \$i=$i\n"; # this provides the same answer but is IMHO much easier to understand m/(.*)(?=lori)/ig; print "pos=", pos; # this is probably the best solution print "index=", index($_, 'lori');
You can't localise and use $i++ in the same statement.
Fixed technical inexactitude thanks jryan
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
In reply to Re: reg-ex frustration
by tachyon
in thread reg-ex frustration
by stratkid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |