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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.