in reply to Re^2: map <IF> to hash with replacement
in thread map <IF> to hash with replacement

map 'returns' a result for each element processed. The result is the last value of the last statement in the map block and may be a list. Consider:

#!/usr/bin/perl use strict; use warnings; my @lines = qw(<tag>A</tag> <TAG>B</TAG> <tag>C</tag>); for my $expr ( 'lc', 'lc($_), 1', '$_=lc($_); s/<tag>//; s/<\/tag>//; $_ => 2' ) { my @values = eval "map {$expr} \@lines"; print join("\n ", "map {$expr} =>", @values), "\n"; }

Prints:

map {lc} => <tag>a</tag> <tag>b</tag> <tag>c</tag> map {lc($_), 1} => <tag>a</tag> 1 <tag>b</tag> 1 <tag>c</tag> 1 map {$_=lc($_); s/<tag>//; s/<\/tag>//; $_ => 2} => a 2 b 2 c 2

That result can be a list (as shown by almut


True laziness is hard work