I think that may all be more trouble than it is worth. One of the big reasons that the warnings pragma came to be was so that warnings didn't have to be an all or nothing proposition.
#!/usr/bin/perl use strict; use warnings; my ($foo, $bar); print '1: ', $foo eq $bar, "\n"; # Uninitialized warning. { no warnings qw( uninitialized ); print '2: ', $foo eq $bar, "\n"; # No warnings emitted. } print '3: ', $foo eq $bar, "\n"; # Warns again.
Update: If you insist on taking the long way though, here's something that might^probably won't help.
Update: Following is the original text of my message. My code is incorrect. It contains a bug whereby it both emits a warning and gives an incorrect result if $x is set to 0 and $y is left undefined. It will not give this result if $x is undefined and $y is 0, however. Ouch. Ewwww. Ugly! Please accept my humble apologies for not thorougly testing.
I believe that:
is equivalent to the shorter and more readable:((defined($x) && defined($y) && ($x eq $y)) || (!defined($x) && !defined($y))
And if you were really playing golf you might write that as:( defined($x && $y) and ($x eq $y) ) or not defined($x || $y)
defined($x&&$y)&&$x eq$y||!defined($x||$y)
Edit and Update: Added readmore tags and show a nasty bug with my definedness shortcuts.
-sauoq "My two cents aren't worth a dime.";
In reply to Re: (Golf) Warningless Comparison
by sauoq
in thread (Golf) Warningless Comparison
by tadman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |