in reply to Re: Re: Regex: plucking numbers from a large string
in thread Regex: plucking numbers from a large string

If you don't need the list, you can of course use the match itself as for's expression.

I thought so, too :(

$ perl -e'$x="1 2 3 4 5 5 5 5 5 5"; $counts[$1]++ for $x=~/(\d)/g; pri +nt "$_ $c ounts[$_]\n" foreach (0..$#counts)' 0 1 2 3 4 5 10
How's that for a wierd problem?

Even stranger, if you s/for/while/:

$ perl -e'$x="1 2 3 4 5 5 5 5 5 5"; $counts[$1]++ while $x=~/(\d)/g; p +rint "$_ $counts[$_]\n" foreach (0..$#counts)' 0 1 1 2 1 3 1 4 1 5 6
This is with 5.6.1.

Ignore me; it makes sense that $1 would be the last value with a for loop. $_ works fine.

$ perl -e'$x="1 2 3 4 5 5 5 5 5 5"; $counts[$_]++ for $x=~/(\d)/g; pri +nt "$_ $counts[$_]\n" foreach (0..$#counts)' 0 1 1 2 1 3 1 4 1 5 6
With a while, you have to use $1; that's confused me.
$ perl -e'$x="1 2 3 4 5 5 5 5 5 5"; $counts[$1]++ while $x=~/(\d)/g; p +rint "$_ $counts[$_]\n" foreach (0..$#counts)' 0 1 1 2 1 3 1 4 1 5 6

--
Mike