Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: tr/// on a list

by grinder (Bishop)
on Sep 14, 2007 at 21:38 UTC ( #639091=note: print w/replies, xml ) Need Help??

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://639091]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2021-01-21 08:53 GMT
Find Nodes?
    Voting Booth?