Go right ahead and pass in the *ARGV
typeglob or \*ARGV
, its reference. Just make sure that the function eventually making use of it does so via the <$fh>
operator or readline($fh)
, its underlying functional equivalent.
The issue addressed in the cited passage from the perlvar manpage is just trying to remind you that you won't be able to get ARGV
’s magic open to trigger if you any use other reading mechanism than readline
on the handle, such as read
, sysread
, or getc
.
Run this to prove to yourself it works:
sub mycat {
my $fh = shift;
print "$ARGV $.: $_" while <$fh>;
}
mycat(*ARGV);
Put that in a file, then run it with several file arguments:
% perl mycat ./mycat //`pwd`/mycat ~/mycat
./mycat 1: sub mycat {
./mycat 2: my $fh = shift;
./mycat 3: print "$ARGV $.: $_" while <$fh>;
./mycat 4: }
./mycat 5: mycat(*ARGV);
///home/tchrist/mycat 6: sub mycat {
///home/tchrist/mycat 7: my $fh = shift;
///home/tchrist/mycat 8: print "$ARGV $.: $_" while <$fh>;
///home/tchrist/mycat 9: }
///home/tchrist/mycat 10: mycat(*ARGV);
/home/tchrist/mycat 11: sub mycat {
/home/tchrist/mycat 12: my $fh = shift;
/home/tchrist/mycat 13: print "$ARGV $.: $_" while <$fh>;
/home/tchrist/mycat 14: }
/home/tchrist/mycat 15: mycat(*ARGV);
See? It works fine.