sophate has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
I have a simple program that passes a file handle as the only argument to a subroutine. <$_[0]> fails to return a line from the file. Instead, it returns something like "GLOB(0x1bcb22a0)". However, if I use another variable to store the file handle. It works!
Anyone has any idea?
#!/usr/bin/perl -w use strict; use warnings; open my $FH, "/tmp/test.txt" || die "Failed to open /tmp/test.txt: $!\ +n"; ## NOT WORKING !! while (my $Line = GetLine($FH)) { print "$Line"; } ## NOT WORKING !! sub GetLine { my $line = <$_[0]> ; return $line; }
If I change the subroutine GetLine to the codes below. It works.
sub GetLine { my $FH = shift; my $line = <$FH> ; return $line; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: $_[0] fails for file handle?
by jwkrahn (Abbot) on Jul 17, 2012 at 04:45 UTC | |
by sophate (Beadle) on Jul 17, 2012 at 04:55 UTC | |
|
Re: $_[0] fails for file handle?
by AnomalousMonk (Archbishop) on Jul 17, 2012 at 17:03 UTC | |
|
Re: $_[0] fails for file handle?
by toolic (Bishop) on Jul 17, 2012 at 13:12 UTC |