Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Replacing with comma

by 2teez (Priest)
on Dec 27, 2012 at 07:37 UTC ( #1010463=note: print w/replies, xml ) Need Help??

in reply to Replacing with comma

You have been given great answers, but If I may add just this.
Using a subroutine with scalar, reverse functions with substitution s///. One can hack a solution like so:

use warnings; use strict; my $foo = "1,2,3"; print modify( $foo, ',', '|' ); ## prints 1,2|3 $foo = "1|2|3"; print modify( $foo, '|', ',' ); ## prints 1|2,3 sub modify { my ( $val, $sep, $rep ) = @_; $val = scalar reverse $val; $val =~ s/\Q$sep\E/$rep/; return scalar reverse $val; }

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1010463]
[zentara]: ... an unatural darkness descends on the realm
[shmem]: eclipse? Java? omg...!

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2017-08-21 18:15 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (324 votes). Check out past polls.