See the last paragraph of print's documentation.
To keep the parser sane, print is very limited as to what it can accept for the file handle argument. It accepts a scalar variable ($fh) or a bare word (FH), and that's probably it unless you wrap the expression in curlies. Inside the curlies can be any Perl expression, including the a hash lookup as desired by the OP.
print { $fh } ...;
print $fh ...; # Shorthand
print { FH } ...;
print FH ...; # Same thing, but also works under strict 'vars'.
print { *FH } ...;
print { $a[$i] } ...;
print { $h{$k} } ...;
print { $o->get_fh() } ...;
print { $e ? *STDERR : *STDOUT } ...;
etc.
|