in reply to Using a filehandle tucked into an array
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using a filehandle tucked into an array
by redbeard (Beadle) on Dec 30, 2006 at 14:58 UTC | |
by jettero (Monsignor) on Dec 30, 2006 at 15:08 UTC |