You're almost there. I'd try something like this: open( $nbdc_filehandles[$index], $filename) or die $!. But $nbdc_filehandles[$index] = \*FILE should work also. I always have trouble reading from an array index though. There's probably a better way to do it, but I end up using my $scalar = $a[0]; my $line = <$scalar>

UPDATE: perlapio always turns out to be a much stranger animal than I ever think. It appears that you can push either \*FILE or *FILE and both work just fine (even though they are different) inside the <>'s — which don't appear to be operators the way I'm used to thinking of them.

use strict; my $f; my $l; my @a = (); open FILE, "/etc/passwd" or die $!; push @a, \*FILE; $f = $a[0]; $l = <$f>; print $l; open FILE, "/etc/passwd" or die $!; push @a, *FILE; $f = $a[1]; $l = <$f>; print $l; open $a[2], "/etc/passwd" or die $!; $f = $a[2]; $l = <$f>; print $l; use Data::Dumper; $Data::Dumper::Indent = $Data::Dumper::Sortkeys = 1; print "", Dumper(\@a), "\n";

See? $a[0] and $a[1] are indeed different. I guess I'm OK with the fact that they both work inside the <>'s but what part of speech is <>? Is that a lexical shortcut to IO::Handle's getline()? I'm sure I figured this out before.

Also, is there a way to read from $a[1] without first setting $f = $a[1]?

-Paul


In reply to Re: Using a filehandle tucked into an array by jettero
in thread Using a filehandle tucked into an array by redbeard

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.