http://qs321.pair.com?node_id=11114912

morgon has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I would like to turn a multiline string that looks like

1 A 2 B
into a hash that looks like
{ 1 => "A", 2 => "B", }
And I tought this was easy enough, however to my surprise this does not work:
use strict; use Data::Dumper; my $s = "1 A\n2 B\n"; my %h =map { $1 => $2 } $s =~ /(\d+)\s+(\S+)/mg; print Dumper(\%h);
It produces
$VAR1 = { '2' => 'B' };
Could someone please explain to me what is going on here?

Many thanks!