J
John Bullock
Hello,
I am puzzled by the behavior of the angle
operator (<>) when it operates on a filehandle
that is passed to a subroutine.
Given filehandle FH, these lines are equivalent:
my $tst1 = <FH>;
my $tst1 = readline(FH);
But if I set up a subroutine, there is an oddity:
do_something(*FH);
sub do_something {
my $tst1;
$tst = $readline($_[0]); # works
$tst1 = <$_[0]>; # doesn't work
$tst1 = < {$_[0]} >; # doesn't work
}
Of course, I can get around this by storing the filehandle
in a scalar that I define in the subroutine. But I want to
understand why neither of the last two lines here works
as intended. (They just leave $tst1 undefined, provided
that it hasn't already been defined.) I've looked to what
I thought were the salient parts of the camel book, but I
had no luck. Can you enlighten me or point me to some
relevant reading?
Thanks,
--John
I am puzzled by the behavior of the angle
operator (<>) when it operates on a filehandle
that is passed to a subroutine.
Given filehandle FH, these lines are equivalent:
my $tst1 = <FH>;
my $tst1 = readline(FH);
But if I set up a subroutine, there is an oddity:
do_something(*FH);
sub do_something {
my $tst1;
$tst = $readline($_[0]); # works
$tst1 = <$_[0]>; # doesn't work
$tst1 = < {$_[0]} >; # doesn't work
}
Of course, I can get around this by storing the filehandle
in a scalar that I define in the subroutine. But I want to
understand why neither of the last two lines here works
as intended. (They just leave $tst1 undefined, provided
that it hasn't already been defined.) I've looked to what
I thought were the salient parts of the camel book, but I
had no luck. Can you enlighten me or point me to some
relevant reading?
Thanks,
--John