I agree with choroba, and just wanted to add that additionally I might consider it acceptable in a longer script to use local @ARGV in a small scope (keeping in mind that this is dynamic scoping, so any function called from within that block will also see the localized values). One neat trick is to combine this with with $^I to do inplace editing of files, like with the -i switch:
$ perl -i -ple '$_.="\n" if $. % 4 == 0; close ARGV if eof' -- FILES
Becomes:
{ # new scope for local local *ARGV; @ARGV = @files; local $^I = ""; # -i command line switch while (<>) { print $_; print "\n" if $. % 4 == 0; close ARGV if eof; } }
(From here.)
Update: Fixed this potential issue in the above example code.
In reply to Re^3: trying to read files in @ARGV but getting GLOB error! (updated)
by haukex
in thread trying to read files in @ARGV but getting GLOB error! :(
by fasoli
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |