in reply to How to eval a tr/// (was: Transliteration!!!)

By the way, now that you have the full-featured, maximally advanced, subtle and idiomatic solution for using variables with "tr///", here's a simple, direct answer to your opening question:
eval "\$var =~ tr/$pattern1/$pattern2/";
Note the use of double quotes around the expression, as well as the backslash in front of "$var". The double quotes will cause interpolation of variables (variables in the string will be replaced by their values); the backslash causes the "$" in "$var" to be passed as a literal, so "eval" gets a string that begins with the four characters '$var', rather than one that begins with the current value (contents) of the variable "$var".

Replies are listed 'Best First'.
Re: Re: How to eval a tr/// (was: Transliteration!!!)
by demerphq (Chancellor) on Oct 21, 2002 at 01:08 UTC
    Ok, you might have a point there. *blush*

    But there is one reason I didn't show just this. If the same transliteration needs to be applied over and over (such as applied to every element of an array) this could be dreadfully slow. And the idea of an anonymous subroutine is common enough that he might as well learn about em now than later.

    :-)

    --- demerphq
    my friends call me, usually because I'm late....