Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: using map and swap (aka substitute)

by AnomalousMonk (Abbot)
on Jan 14, 2013 at 21:40 UTC ( #1013284=note: print w/ replies, xml ) Need Help??


in reply to using map and swap (aka substitute)

What should be done instead:

my @list= qw(first_string second_string); @list = map((s/_string$// and $_), @list); print @list;

This should be done only if one wishes to reduce all strings on which no substitution is done to empty strings:

>perl -wMstrict -le "my @list= qw(first_string second_string THIRD fourth_string); @list = map((s/_string$// and $_), @list); printf qq{'$_' } for @list; " 'first' 'second' '' 'fourth'

If this is not the case, BrowserUk has shown some alternatives.


Comment on Re: using map and swap (aka substitute)
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (17)
As of 2015-07-02 10:02 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 (33 votes), past polls