Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1010463]
help
Chatterbox?
[erix]: job hunting is an annoying situation to be in. Of course, once settled somewhere you're going to want out again...
[erix]: but that doesn't make the searching less anoying
[Tanktalus]: I've been looking for over 12 months :(

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2017-05-23 19:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?