Aaron Sherman writes: > 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!
you're assuming a particular implementation of tr in which it iterates over the hash in default order on every character. being a fan of dfas myself, it might compile a dfa of those substitutions and find out that it's ambiguous right off the bat. or not. the point is that it's only undefined for certain implementations, and if we're smart, we'll use an implementation for which it is not undefined. but you're right, it could also take ordered pairs and disambiguate based on that. that actually seems like a better way to go, since "A-Z" isn't really a hash key but a pattern/replacement. looking up "X" in the hash won't bring you to "A-Z"'s value, so pairs sounds better to me. luke