[Pdx-pm] evil @ARGV syntax
Eric Wilhelm
ewilhelm at sbcglobal.net
Tue Jul 19 12:50:25 PDT 2005
# from Michael G Schwern
# on Tuesday 19 July 2005 12:14 pm:
>On Tue, Jul 19, 2005 at 11:05:05AM -0700, Randall Hansen wrote:
>> which seems like a complicated way of writing:
>>
>> if( @ARGV < 1 or @ARGV > 2 ) {
I'm guessing the next step is to die with a usage message or otherwise
complain about the number not being 1|2
>The ironic thing is this is all a really complicated way of saying the
> much more natural:
>
> # if I got 1 or 2 args...
> if( @ARGV == 1 or @ARGV == 2 ) {
> ...
> }
You've reversed the intent though.
unless(@ARGV == 1 or @ARGV == 2) {
die "you must guess the correct number of arguments\n";
}
Maybe they started in a language without an "unless" or for some other
reason chose to write the negative form of the OK condition instead of
negating the OK condition.
if(not (@ARGV == 1 or @ARGV == 2)) {
I prefer to use unless(everything_is_okay()) since I think it reads
better. If Randall is in the sweet vengeful position of being able to
return maintenance to the original author, maybe he would like to
initiate a perl crash-course with the more conversational:
unless(scalar(@ARGV) =~ m/^(?:1|2)$/) {
Of course that's a little hairbrained, but I don't see any functional
holes in it right now.
IIRC, perl6 going to have something like (like!) $num == $this or $that,
which is pronounced the same as the above but with less stuttering.
--Eric
--
"Everything goes wrong all at once."
--Quantized Revision of Murphy's Law
---------------------------------------------
http://scratchcomputing.com
---------------------------------------------
More information about the Pdx-pm-list
mailing list