Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: How to substitute the elements in an array without changing the original array.

by Firefly258 (Beadle)
on Dec 02, 2006 at 00:46 UTC ( [id://587349]=note: print w/replies, xml ) Need Help??


in reply to How to substitute the elements in an array without changing the original array.

I tend to use a few tricks with map and grep to preserve the original array than to seek out and use something different.
@new = map { ... } @{[ @original ]};
or even
@new = grep { local $_ = $_; ... } @original;
If legibility (management overhead due to fussy boss) is a concern, I then choose to use an idomatic version of the for / do { ... } for loop.
... for @new = @original;
or if you want multiple expressions within the loop..
do { ...; ... } for @new = @original;


perl -e '$,=$",$_=(split/\W/,$^X)[y[eval]]]+--$_],print+just,another,split,hack'er

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-26 05:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found