perl -e '$a="1b2cde5";for($a=~/(\d+)/g){$t+=$1;};print "$t\n";' perl -e '$a="1b2cde5";for($a=~/(\d+)/g){$t+=$_;};print "$t\n";'
The first one prints 15. The second one prints 8.
My confusion is with the first one. I can understand it's taking the rightmost match, but in that case why does the loop iterate three times? I would have thought if the loop iterated three times, it would put different values into $1 each time. I'm trying to understand this one. Any explanations appreciated. This is perl 5.8.4.
In reply to Looping on a match, and value of $1 by dmorgo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |