Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

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

Comment on Re: Replacing with comma
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2015-11-28 08:55 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (740 votes), past polls