daiyu has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: why doesn't this work
by chromatic (Archbishop) on Aug 24, 2011 at 01:26 UTC | |
|
Re: why doesn't this work
by CountZero (Bishop) on Aug 24, 2011 at 08:39 UTC | |
|
Re: why doesn't this work
by charlesboyo (Beadle) on Aug 24, 2011 at 06:31 UTC | |
|
Re: why doesn't this work
by RichardK (Parson) on Aug 24, 2011 at 09:20 UTC | |
by roboticus (Chancellor) on Aug 24, 2011 at 09:52 UTC | |
|
Re: why doesn't this work
by Anonymous Monk on Aug 24, 2011 at 05:03 UTC |