How to read from a method that returns a filehandle in perl?

Posted by Ryan Thompson on Stack Overflow See other posts from Stack Overflow or by Ryan Thompson
Published on 2010-04-20T02:37:20Z Indexed on 2010/04/20 2:43 UTC
Read the original article Hit count: 304

Filed under:
|
|

I have an object with a method that returns a filehandle, and I want to read from that handle. The following doesn't work, because the right angle bracket of the method call is interpreted as the closing angle bracket of the input reader:

my $input = <$object->get_handle()>;

That gets parsed as:

my $input = ( < $object- > ) get_handle() >;

which is obviously a syntax error. Is there any way I can perform a method call within an angle operator, or do I need to break it into two steps like this?

my $handle = $object->get_handle();
my $input = <$handle>;

© Stack Overflow or respective owner

Related posts about perl

Related posts about filehandle