in reply to tr/// on a list

it seems not terribly perlish.

Well actually, a foreach is actually quite perlish. To be terribly perlish, one would shorten it down to a for modifier that operates on $_ implicitly aliasing over each element

for (@beatles) { tr /A-Z/a-z/ }

written more concisely as

tr /A-Z/a-z/ for @beatles;

which is probably more elegant than a vulgar map.

@beatles = map {lc} @beatles;

update: gah! I do ramble on.

• another intruder with the mooring in the heart of the Perl

Replies are listed 'Best First'.
Re^2: tr/// on a list
by GrandFather (Saint) on Sep 14, 2007 at 22:37 UTC

    Because map operates on an alias of each element you don't need to assign the result of the map anywhere:

    map {$_= lc} @beatles;

    However map in a void context is frowned on so it would be more usual to use for/foreach as a statement modifier:

    $_ = lc for @beatles;

    DWIM is Perl's answer to Gödel