in reply to Reference is experimental

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:  <%-{-{-{-<