What Perl actually is using when giving you the  print FH $foo; syntax is the indirect object syntax. Often hated, with good reasons. However, for print and printf it's still used a lot and personally I prefer to use it there too, but that's probably the only exception.

Anyway, to the real issue here. You have the filehandle stored in something that's not a plain scalar. Knowing that the syntax above is OO syntax, it can be rewritten to
use IO::Handle; $files{$self->{_filetype}}->print($entry);
and it should work as expected. (Here I wonder what's really going on though. Because not only does print FH EXPR work without loading IO::Handle. You can also parenthesize it in a way you normally can't do with indirect object syntax: print(FH EXPR). Compare to parse($html_parser $chunk).)

However, you might not want to do that. Looking at the Perl grammar (where else is this documented, except as a brief note in perlfunc?) we see that the indirob (indirect object) rule can be not just a word (for classes), scalar (for objects), but also a block. (And then there's a PRIVATEREF thing that I don't know what it is. Anyone?)   print { $files{$self->{_filetype}} } $entry; But this means that print is not special in this aspect (or at least not in principle). Having a block to resolve the object can always be done. These two lines below are generally analogous:
do BLOCK -> method(LIST); method BLOCK LIST;
Not that I find myself wanting any of these that often though. I usually find myself doing well with just EXPR->method(LIST).

However, I've never seen this indirect block object syntax before on anything but print/printf. Perhaps that's partly due to lack of explanation and documentation in perlobj? (Not that we want to make people start abusing indirect block object syntax, but it's needed for deeper understanding.) Or have I missed the documentation for this?

Hope I've helped,
ihb

In reply to Re: Filehandles in a Hash by ihb
in thread Filehandles in a Hash by Flawless_koder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.