#by Janek Schleicher #favor using a module: use Regexp::Subst::Parallel; my $replaces_str = subst($string, qr/A/ => 'Y', qr/B/ => 'Z' ); ###################################### #Discussion: #using a hash my %substitute = (A => 'Y', B => 'Z'); my $keys = join "|", keys %substitute; s/($keys)/$substitute{$1}/g; #Disadvantages are that it becomes slow, #when there a lot of different expressions, #and it can lead to problems if there are some regexp characters insid +e. ############################################### #It's often extremely useful, #if you know that the matches can be matched with a more general one, #e.g. they are words: s/(\w+)/$substitute{$1} || ""/ge;
In reply to Re: Looking for a Better Way to Substitute Characters (accents to HTML)
by zentara
in thread Looking for a Better Way to Substitute Characters (accents to HTML)
by svsingh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |