hello: this is coming from a novice so pls be kind. want to key a set of filehandles in a hash, along the following lines:
open $hash{'t'},"test.txt"; ... @lines = <$hash{'t'}>; print @lines; # end up with a GLOB pointer, # not the contents of the file close $hash{'t"];
however when I code this way I get a GLOB reference. In order to print out the actual contents of the file I have to gimmick the filehandle as follows:
open $hash{'t'},"test.txt"; $a = $hash{'t'}; # pass the hash value # to another scalar @lines = <$a>; # and suddenly grabbing the @lines print @lines; # results in correct output! ...
Granted this is an easy enough workaround in practice. But I would like to understand why it appears to be necessary to pass the filehandle in $hash{'t'} to $a before <$a> returns correct output to @lines. This is not great way to do it, and I suspect there's some form of dereferencing that could eliminate the need for the intermediary assignment to $a. Thanks for any thoughts!
In reply to why doesn't this work by daiyu
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |