in reply to Defaults for command line args

this isn't really "better", but it looks nicer:
my $infileold = (@ARGV) ? shift @ARGV : "ArchLDAP"; my $infilenew = (@ARGV) ? shift @ARGV : "LDAP";

Replies are listed 'Best First'.
RE: Re: Defaults for command line args
by ZZamboni (Curate) on May 15, 2000 at 22:32 UTC
    The problem with this is that @ARGV could be non-empty but its elements could be undef or empty strings. So your test for "if (@ARGV)" would pass, but the variable would get assigned an empty string. Consider what happens if the scripts is called like this:
    ./prog.pl ""
    In this case @ARGV is not empty, but its first element is an empty string.

    --ZZamboni

      yeah, i thought of that, but i was over editing my answer when i saw three other answers which together covered every aspect of the problem. i think the best is btrott's solution:
      my $infileold = shift || $fileold;