Further to davido's ++post: A more Perlish way to write this kind of loop (and the subsequent print loop) might be (using several other suggestions from this thread):

my @AoA; for my $filename (@ARGV){ open my $filehandle, '<', $filename or die "opening '$filename': $ +!"; my (undef, @tmp) = <$filehandle>; push @AoA, \@tmp; close $filehandle; } foreach my $aref (@AoA){ print "\t [ @$aref ],\n"; }
The for-loop iterates over the @ARGV array and that's that; you don't have to worry about managing $counter or depleting @ARGV, and the $filename variable is entirely local to the scope of the for-loop (as is $aref in the following print loop), and thus cannot conflict with the same variable name in an enclosing scope (but see below!).

Update:

... thus cannot conflict with the same variable name in an enclosing scope.
This statement is a bit misleading. A lexical for-loop iteration variable is completely localized within the scope of the loop regardless of whether or not a new lexical is declared for this purpose:
c:\@Work\Perl\monks>perl -wMstrict -le "my $x = 'eks'; print qq{before loop: $x}; ;; for my $x (1, 2, 3) { print qq{in loop: $x}; } ;; print qq{after loop: $x}; " before loop: eks in loop: 1 in loop: 2 in loop: 3 after loop: eks c:\@Work\Perl\monks>perl -wMstrict -le "my $x = 'eks'; print qq{before loop: $x}; ;; for $x (1, 2, 3) { print qq{in loop: $x}; } ;; print qq{after loop: $x}; " before loop: eks in loop: 1 in loop: 2 in loop: 3 after loop: eks
Thus, the only "conflict" that can arise is due to confusion in the mind of the programmer. :)


Give a man a fish:  <%-{-{-{-<


In reply to Re: Reference is experimental by AnomalousMonk
in thread Reference is experimental by Anonymous Monk

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.