OK, I'm stumped. I'm trying to read from a file handle in a while loop. The reference to the file handle is in a hash which itself begins with a hash reference like this ...
my $cfg = {};
open (INFILE,"<testfile.txt") || die "Could not open file\n$!\n";
$$cfg{infile} = \*INFILE;
while(<$$cfg{infile}>){
print "$_\n";
}
__END__
GLOB(0x20eab18)
However, when I do it this way, it works as expected.
my $cfg = {};
open (INFILE,"<testfile.txt") || die "Could not open file\n$!\n";
$$cfg{infile} = \*INFILE;
my $infh = $$cfg{infile};
while(<$infh}>){
print "$_\n";
}
I figure that the angle operator is not dereferencing $$cfg{infile} as I want but I cannot come up with a combinations of parens, curly braces and arrows that will make this work. What am I missing?
Update: I knew I was missing the obvious. Thanks Roy. :o)
PJ
Unspoken but ever present -- use strict; use warnings; use diagnostics; (as needed)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.