in reply to script for deleting html, images and css from server
which does not work because of the low precedence of or (compared to eq), so that this is parsed essentially as if you had written:die unless ( $answer eq 'Y' or 'y' );
The right-hand part of the or operator is always true so that even if the user type "N", the condition will always be true. (Note that even using the higher precedence || operator would not help, because its precedence is still lower than the precedence of the eq operator.)die unless ( ($answer eq 'Y') or ('y') );
Deparsing the statement shows this:
$ perl -MO=Deparse,-p -e 'die unless ( $answer eq "Y" or "y");' ((($answer eq 'Y') or 'y') or die); -e syntax OK
In Perl 6, though, using an any junction infix operator would allow you to do something similar that would work the way you expected:
> my $answer = "y"; y > say "true" if $answer eq 'Y' | 'y'; true > say "true" if $answer eq 'N' | 'y'; true > say "true" if $answer eq 'N' | 'n'; Nil >
|
|---|