Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: using map and swap (aka substitute)

by BrowserUk (Pope)
on Jan 14, 2013 at 20:24 UTC ( #1013271=note: print w/ replies, xml ) Need Help??


in reply to using map and swap (aka substitute)

Since you are overwriting the original array with the results, the simplest solution is:

s/_string$// for @list;

Which mutates the array in-place, thus avoids constructing two lists (in and out of map) as well as 'curing' the perceived problem.

And if you wanted to create a new list from the modified values whilst retaining the original array unmodified, I'd probably do it this way also:

my @list = ...; my @newList = @list; s/_string$// for @newList;

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re: using map and swap (aka substitute)
Select or Download Code
Replies are listed 'Best First'.
Re^2: using map and swap (aka substitute)
by jwkrahn (Monsignor) on Jan 14, 2013 at 22:45 UTC
    my @newList = @list; s/_string$// for @newList

    Or just:

    s/_string$// for my @newList = @list;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (19)
As of 2015-07-28 14:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (255 votes), past polls