John wrote:
Is there a way to use variables in a translation? I'm looking for a way
to use, for example, $x = "abc" and $y = "ABC" so something like
y/$x/$y/;
behave like
y/[abc]/[ABC]/;
The tr/// operator doesn't interpolate so you have to do something like:
eval y/$x/$y/;
Or perhaps:
my %translate;
@translate{ split //, $x } = split //, $y;
s/([$x])/ $translate{ $1 } /eg;
Or if you just want to upper case certain letters then:
s/([$x])/\U$1/g;
Just curious, in y/[abc]/[ABC]/; why are you translating all '['
characters to '[' and all ']' characters to ']'?
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/