Ever find yourself wrangling in a map when you're trying to change each element of a list to a new value via s/// or tr/// only to recall that substitution or transliteration returns a count, not the changed string? So you end up doing something ugly like:
@new = map { my $x = $_; $x =~ s/foo/bar/g; $x } @old;
That's just because you're doing it inside out. Much simpler to use a foreach loop, as shown in this snippet.
s/foo/bar/g for (@new = @old); - or - tr/A-Z/N-ZA-M/ for (@new = @old);

Replies are listed 'Best First'.
(jcwren) RE: make a new list by substituting an old list
by jcwren (Prior) on Sep 10, 2000 at 21:39 UTC
    Is there something wrong with this, then?
    my @new = map {s/foo/bar/g; $_} @old;
    --Chris

    e-mail jcwren
        See what happens when you let small children play with sharp regexps? <G>

        (I knew I should have asked Ovid about that first...)

        --Chris

        e-mail jcwren