Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: using map and swap (aka substitute)

by AnomalousMonk (Canon)
on Jan 14, 2013 at 22:09 UTC ( #1013288=note: print w/replies, xml ) Need Help??

in reply to using map and swap (aka substitute)

With 5.14+, the  /r modifier can be used with  s/// substitution to achieve non-mutating substitution with return of a copy of the string (although the intermediate array creation by map noted by BrowserUk will, I think, still occur). See  s/// in the Regexp Quote-Like Operators section of perlop:

If the "/r" (non-destructive) option is used [in s///] then it runs the
substitution on a copy of the string and instead of returning
the number of substitutions, it returns the copy whether or not
a substitution occurred. The original string is never changed ...
>perl -wMstrict -le "my @list= qw(first_string second_string THIRD fourth_string); my @newlist = map s/_string$//r, @list; printf qq{'$_' } for @list; print ''; printf qq{'$_' } for @newlist; " 'first_string' 'second_string' 'THIRD' 'fourth_string' 'first' 'second' 'THIRD' 'fourth'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1013288]
[marioroy]: LA only $ and \ needed backslash, not ' and ".
[marioroy]: my @music_times = qx(find \$HOME/Music/ Albums -type f -iname '*.mp3' -exec mp3info -p "%S\\n" {} \\;);
[marioroy]: I wanted to come back and report on that.
[marioroy]: cheers

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2017-04-23 22:38 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (433 votes). Check out past polls.