in reply to Re: Using @ARGV
in thread Using @ARGV

Just to clarify this line from thundergnat's post:
open my $fh, shift or die "Cannot open file: $!\n";
shift(), when used outside a subroutine shifts the first element off @ARGV. Another way of accessing the first element would be:
open my $fh, $ARGV[0] or die "Cannot open file: $!\n";

See also perldata, perlvar and shift

Replies are listed 'Best First'.
Re^3: Using @ARGV
by merlyn (Sage) on Dec 03, 2005 at 18:50 UTC
      This construct pulls filenames from the @ARGV array, automatically.

      It also introduces some potential security risks if used wantonly, as described in Dangerous diamonds!. These risks are frequently acceptible, and I'm sure you're already aware of them, but I feel it's something worth mention for the benefit of others. :-)

      Update: thought it might be good to mention the original code uses two-arg open anyway, so switching to <> doesn't add any security risks that weren't already there.

      Another update: quick note about merlyn's reply. I wasn't really "that concerned", which is what I was trying to say when I wrote "these risks are frequently accept[a]ble." Maybe that wasn't very clear.