[Pdx-pm] evil @ARGV syntax

Randall Hansen randall at sonofhans.net
Tue Jul 19 11:05:05 PDT 2005

folks ~

i'm refactoring some gnarly old code that has no tests.  it's mostly  
baby perl, or worse.  there's this line:

     if( $#ARGV + 1 < 1 || $#ARGV + 1 > 2 ) {

which seems like a complicated way of writing:

     if( @ARGV < 1 or @ARGV > 2 ) {

i've tested this and found it to be true.  my question is, why on  
earth would someone write this the first way?  it's one thing not to  
understand scalar context; it seems entirely insane to add those ones  
before the less|greater than tests.

am i missing an idiom?  historical reason?  does @ARGV behave oddly  
enough in certain contexts that these gymnastics are necessary?



More information about the Pdx-pm-list mailing list