How to read from a method that returns a filehandle in perl?
- by Ryan Thompson
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>;