Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: array with s///g command

by liverpole (Monsignor)
on Jul 30, 2007 at 00:04 UTC ( [id://629457]=note: print w/replies, xml ) Need Help??


in reply to Re: array with s///g command
in thread array with s///g command

I like brief too ... why not simply:?
my @array2 = map { s/\s+//g; $_ } @array1;

Update  Whoops, now I see ... it's because you'd be changing the original array.  Still, I like the brevity of something like:

my @array2 = map { (my $x = $_) =~ s/\s+//g; $x } @array1;

s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^3: array with s///g command
by GrandFather (Saint) on Jul 30, 2007 at 00:28 UTC

    Because that mangles @array1 - $_ is aliased to each element from @array1 and the substitution clobbers the original value


    DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-25 13:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found