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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |