evan@cs.mu.OZ.AU (Evan Harris) (02/26/91)
The following code: $foo = '*foo'; $foo =~ tr/a-zA-Z//c; print "$foo\n"; does not produce the output (I) expected. Changing the * to (say) . produces a different (but similar) result. Platforms: Sun 3, 4; SunOS 4.1, 4.1.1; Perl 3.044, 4.0beta. --------------------------------8<-------------------------------- Evan Harris Dept. of Computer Science evan@cs.mu.OZ.AU The University of Melbourne, Australia
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (02/27/91)
In article <EVAN.91Feb26154539@murgon.cs.mu.OZ.AU> evan@mullauna.cs.mu.OZ.AU writes:
: The following code:
: $foo = '*foo';
: $foo =~ tr/a-zA-Z//c;
: print "$foo\n";
: does not produce the output (I) expected. Changing the * to (say) .
: produces a different (but similar) result.
You need to tell it what you want to translate non-alphabetic characters to.
In the absence of a RHS, it'll simply reuse the LHS (unless you supply a d,
in which case it will delete the specified characters). So you've
essentially said
$foo =~ tr/a-zA-Z/a-zA-Z/c;
Now, that said, I should say that there's a bug up through 4.0 beta that
incorrectly replicates the last character of the RHS when complementing,
which is why
$foo =~ tr/a-zA-Z/_/c;
doesn't work right. It's fixed in real 4.0 though.
Larry