angle operator behavior with filehandles in @_

From: John Bullock (john.bullock_at_stanford.edu)
Date: 08/29/04


Date: Sat, 28 Aug 2004 22:35:56 -0700


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



Relevant Pages

  • Re: angle operator behavior with filehandles in @_
    ... I can get around this by storing the filehandle ... > in a scalar that I define in the subroutine. ...
    (comp.lang.perl.misc)
  • Re: filehandle to a member of a zip archive
    ... way I can make my subroutine take in a barwood operator for the ... you meant "bareword filehandle" instead. ... You can pass a type glob, or a reference to a type glob as ... How can I make a filehandle local to a subroutine? ...
    (comp.lang.perl.misc)
  • Re: use strict and filehandles
    ... > subroutine identifier, in curly brackets or to the left of the ... Using a bare word in the filehandle ... In this case a bare word does everything I need ... I guess use strict is trying to make sure I ...
    (perl.beginners)
  • RE: use strict and filehandles
    ... If you want to pass a filehandle like that I would recommend using the ... I'm running into a Cach-22 with 'use strict', ... files, e.g. in code sample A below, ERRLOG and INFLOG are declared at ... A subroutine tries to pass 'ERRLOG' or 'INFLOG' to the 'log' ...
    (perl.beginners)
  • Re: angle operator behavior with filehandles in @_
    ... I can get around this by storing the filehandle ... > in a scalar that I define in the subroutine. ...
    (comp.lang.perl.misc)