Dear monks,
I'm trying to do something that should be really simple, but it's not Doing What I Mean.
Somewhere in the code I am calling a $parser, and pass it, among other things, a file handle to read from (at least, that's the idea):
open(FH, $opts{-file});
$opts{-handle} = \*FH;
$parser->from_handle(%opts);
So, I have a hash %opts, that contains a file path under the -file key. I open the file, create a reference to the handle, assign that to $opts{-handle} and send the whole %opts hash to the $parser->from_handle method. Then, over in the from_handle method, the following happens:
sub from_handle {
my $self = shift;
my %opts = @_;
while (<$opts{-handle}>) {
#... and here we're supposed to read from FH
}
}
Okay, so in the "while" loop I was hoping $_ would contain the contents of $opts{-file}, one line at a time. Instead, it contains "GLOB(0x18660a8)". I've read perldata and perlref but I'm not quite sure what is expected of me. I tried *FH{IO} and desparate permutations with or without slashes in front of *FH, but they don't give me what I want.
I am obviously doing something wrong, but I don't quite know what The Right Way is. Any help and code examples are greatly appreciated. Thanks!
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.