in reply to regex question
morgon: Further to Corion's post:
[Corion]: The match runs to completion before the map even starts.Here's an instrumented version of the OPed code to better (I hope) show what's happening:
At the time your map runs, $1 and $2 are what they are at the end of the global match.
(Note that this example doesn't take into account the revised data format specification suggested here. :)c:\@Work\Perl\monks>perl -wMstrict -le "use Data::Dumper; ;; my $s = \"1 A\n2 B\n33 foo\n\"; ;; my %h = map { print qq{in map: \$_ '$_' \$1 '$1' \$2 '$2'}; $1 => $2; } $s =~ /(\d+)\s+(\S+)/mg ; print Dumper(\%h); " in map: $_ '1' $1 '33' $2 'foo' in map: $_ 'A' $1 '33' $2 'foo' in map: $_ '2' $1 '33' $2 'foo' in map: $_ 'B' $1 '33' $2 'foo' in map: $_ '33' $1 '33' $2 'foo' in map: $_ 'foo' $1 '33' $2 'foo' $VAR1 = { '33' => 'foo' };
Give a man a fish: <%-{-{-{-<
|
---|