http://qs321.pair.com?node_id=11123246


in reply to Dereference a reference to a file handle created with IO::File

Refer print:
FILEHANDLE may be a scalar variable containing the name of or a reference to the filehandle,...

UPDATE: Changed emphasis per Tobyink (below)

Bill
  • Comment on Re: Dereference a reference to a file handle created with IO::File

Replies are listed 'Best First'.
Re^2: Dereference a reference to a file handle created with IO::File
by tobyink (Canon) on Oct 28, 2020 at 08:41 UTC

    Yeah, this is a place you need to pay careful attention to the wording. It has to be a scalar variable, not just a scalar.

    Like foo() could return a scalar, and that scalar could be a reference to a filehandle. But print foo() "string\n" will fail because even though foo() evaluates to a scalar, it's not a scalar variable. Nor is $foo{'somekey'}.

    Same as you're not allowed to do:

    my %foo; for $foo{'somekey'} ( @arr ) { ...; }