You'll have to do two things.

(1) As pointed out by others, <SOMETHING> is ambiguous. It's either a filehandle read or a directory glob (to get the list of files that match a pattern:

$line = <$filehandle>; # simple scalar variable = read op @files = <*.c>; # anything else is a directory glob
As the comments there say, the rule is: If it's a simple scalar variable, it's a filehandle. If it's a bare word it's a filehandle. Anything else and it's a directory glob.

So you'll need to use a temporary variable:

$tmp = $this->{THAT}->[0]->{THE_OTHER}; $line = <$tmp>;
(2) You won't be able to successfully open more than one file (even if you hadn't hard-coded the filename :-). A common hack in Perl to get filehandles in arrays or hashes or subroutines is to use typeglobs, because Perl lets you use a scalar containing a typeglob anywhere you would normally use a filehandle. However, there's some cunning required when opening the file:

open FH, $file1 or die; # open it, okay ... push @filehandles, *FH; # push the typeglob, fine ... open FH, $file2 or die; # reopening it, closing the previously open +ed file! push @filehandles, *FH; # push it again
This gives you two copies of the same glob in @filehandles. What you need to do is create a new glob each time. The best way to do this is with local():

sub open_file { my ($self, $filename) = @_; local *FH; open FH, $filename or die "opening $filename: $!"; $self->{FH} = *FH; }

Good luck!

Nat


In reply to RE: File handles in an object by gnat
in thread File handles in an object by sluap

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.