In S5, the following is stated:

        The tr/// quote-like operator now also has a subroutine form.
        
      * It can be given either a single PAIR:
        
            $str =~ tr( 'A-C' => 'a-c' );
      * Or a hash (or hash ref):
        
            $str =~ tr( {'A'=>'a', 'B'=>'b', 'C'=>'c'} );
            $str =~ tr( {'A-Z'=>'a-z', '0-9'=>'A-F'} );
            $str =~ tr( %mapping );

I don't think that hashes of translation patterns should be allowed.
It's just too dangerous and too likely to result in hours of trying to
understand why tr is doing "the wrong thing", but only sometimes.

Specifically, hashes do not maintain ordering, so a program like this:

        $downcaserule = 'A-Z' => 'a-z';
        $l33trule = 'EISTA' => '31574';
        $str =~ tr( { $l33trule, $downcaserule } );

may or may not do what the naive reader expects, and randomly so!

I'd much rather that tr simply take an ordered list of pairs.

-- 
â 781-324-3772
â [EMAIL PROTECTED]
â http://www.ajs.com/~ajs

Reply via email to