If tr doesn't use patterns then please help me understand how it works 
in my test cases? 

btw a straight swap to s/// fails for true == 1 but works for true ==
'foo'.


#!/usr/bin/perl

for (1,'foo',0) {
        $a = $_;
        test();
        test();
}
sub test {
        print "$a ";
        if ($a=~tr/.[^0]+/0/cs) { do_something(); }
        print "$a\n";
}

sub do_something {
        print " -> ";
}

output:
1  -> 0
0 0
foo  -> 0
0 0

On Wed, 22 May 2002, Yanick wrote:

> On Wed, May 22, 2002 at 10:06:39PM -0400, Josh Goldberg wrote:
> > I came up with another one.  This also works for values of true other
> > than 1.
> > 
> > if ($a=~tr/.[^0]+/0/c) { do_something(); }
> 
>       s/tr/s/, maybe ?
> 
>       (the transliterate operator doesn't use patterns, so
>       the code above change every instances of '.' by a 0,
>       of '[' by a '[' and so on and so forth...)
> 
> 
> Joy,
> `/anick
> 
> -- 
> On the whole, human beings want to be good, 
> but not too good, and not quite all the time.
>                              -- George Orwell
> 

Reply via email to