in reply to Combining multiple =~ s/
Let Perl generate the regular expression from a hash containing the list of words and their replacements:
my %trans = (zero => 0, one => 1, two => 2, three => 3); my $words_re = join "|", map quotemeta, keys %trans; $string =~ s/($words_re)/$trans{lc $1}/ig;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Combining multiple =~ s/
by Corion (Patriarch) on Mar 07, 2021 at 19:10 UTC | |
by no longer just digit (Beadle) on Mar 10, 2021 at 06:54 UTC | |
Re^2: Combining multiple =~ s/
by LanX (Saint) on Mar 07, 2021 at 20:44 UTC |
In Section
Seekers of Perl Wisdom