Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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


Comment on Re: Replacing with comma
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-12-21 08:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (104 votes), past polls