in reply to Re: map it back jack
in thread map it back jack

Many people frown on using map and grep in a void context. Both commands are intended for building a list that is returned at the end; if you don't need the returned list from map or grep, it's cleaner to use foreach instead.
my %myhash; foreach (@elements) { my $v = $_; $v =~ tr/_/ /; $myhash{$_} = $v; }
UPDATE: runrig pointed out that the my $v can be moved inside the loop, which didn't occur to me as I was rewriting the map to a foreach. I've made that change now.

Replies are listed 'Best First'.
Re: Re: Re: map it back jack
by Hot Pastrami (Monk) on Dec 16, 2000 at 03:11 UTC
    Alrighty, thanks for the tip.

    Hot Pastrami