in reply to hash assignment using map with multiple statements

And also like foreach, we can do hash assignments inside the map.
map { my $val = (split /\//, $_)[-1]; (my $key = $val) =~ s/\.txt//; $testhash1{$key} = $val } @teststr;

Replies are listed 'Best First'.
Re^2: hash assignment using map with multiple statements
by chromatic (Archbishop) on Sep 19, 2008 at 15:52 UTC

    Why would you do that? Just about everyone who sees map expects that the code is transforming one list into another list, not performing a block of code for each element of a list. There's a perfectly good way to indicate that you're performing a block of code for each element of a list; why make your code less clear?