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
into a hash that looks like1 A 2 B
And I tought this was easy enough, however to my surprise this does not work:{ 1 => "A", 2 => "B", }
It producesuse strict; use Data::Dumper; my $s = "1 A\n2 B\n"; my %h =map { $1 => $2 } $s =~ /(\d+)\s+(\S+)/mg; print Dumper(\%h);
Could someone please explain to me what is going on here?$VAR1 = { '2' => 'B' };
Many thanks!
Back to
Seekers of Perl Wisdom