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!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: regex question
by Corion (Patriarch) on Apr 01, 2020 at 17:16 UTC | |
Re: regex question
by AnomalousMonk (Archbishop) on Apr 01, 2020 at 17:51 UTC | |
Re: regex question
by AnomalousMonk (Archbishop) on Apr 02, 2020 at 01:45 UTC | |
Re: regex question
by hippo (Bishop) on Apr 01, 2020 at 17:53 UTC | |
by morgon (Priest) on Apr 01, 2020 at 19:34 UTC | |
by AnomalousMonk (Archbishop) on Apr 01, 2020 at 23:08 UTC | |
by rsFalse (Chaplain) on Apr 02, 2020 at 15:17 UTC | |
Re: regex question
by tybalt89 (Monsignor) on Apr 01, 2020 at 17:51 UTC |
Back to
Seekers of Perl Wisdom