Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Replace multiple strings in a string

by BillKSmith (Priest)
on May 07, 2014 at 20:36 UTC ( #1085376=note: print w/replies, xml ) Need Help??


in reply to Replace multiple strings in a string

Do them all at once.
use strict; use warnings; my %replacement = ( '?a?' => 'aRep', '?b?' => 'bRep', '?c?' => 'cRep', ); my $regex = join '|', keys %replacement; $regex =~ s/\?/\\\?/g; my $string = '?a? ?b? ?c?'; print "old string: $string\n"; $string =~ s/($regex)/$replacement{$1}/ge; print "new string: $string\n";
Bill

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1085376]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2017-03-23 00:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (278 votes). Check out past polls.