Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^5: substitute characters in the RHS of a search & replace

by LanX (Chancellor)
on Mar 09, 2013 at 20:07 UTC ( #1022620=note: print w/replies, xml ) Need Help??


in reply to Re^4: substitute characters in the RHS of a search & replace
in thread substitute characters in the RHS of a search & replace

I think a call on @something should rather generate a warning instead of trying DWIM.

But no (good) idea how to implement that.

Maybe better iterate over all arguments and returning a list? something called rxmap maybe?

Cheers Rolf

Replies are listed 'Best First'.
Re^6: substitute characters in the RHS of a search & replace
by AnomalousMonk (Canon) on Mar 09, 2013 at 21:04 UTC

    Hmmm...     This is the best I could do, but it's a bit icky for Anonymonk's OPed application:

    >perl -wMstrict -le "sub rx (&@) { return map { local $_ = $_; ()= $_[0]->(); $_; } @_[1..$#_]; } ;; my $s = 'a b c d'; print rx { s/ /_/g } $s; ;; my @ra = ('p q r', 'x y z z y'); print rx { s/ /_/g } @ra; ;; my $x = q{Here are [[a [[ variable]] number [[of ]words]] in brackets}; print qq{'$x'}; ;; $x =~ s( \[\[ (.*?) \]\] )( (rx {s/ /_/g} $1)[0] )xmsge; print qq{'$x'}; " a_b_c_d p_q_rx_y_z_z_y 'Here are [[a [[ variable]] number [[of ]words]] in brackets' 'Here are a_[[_variable number of_]words in brackets'

    Bottom line:  s///r is a lot nicer. Thanks again to whoever thought of that one.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1022620]
help
Chatterbox?
[Corion]: Hi Discipulus!
[Discipulus]: your chautauqua was important for me
[Discipulus]: Hi Corion here is holiday: the best we have Liberation Day
[Discipulus]: waiting sons to finish home assignments and we go out to some park
[Corion]: Discipulus: Oh ;) I'm looking forward to 1st of May - the next holiday here ;)

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2017-04-25 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (449 votes). Check out past polls.