[boulder.pm] hash for multiple filehandles?
Rob Nagler
nagler at bivio.com
Wed Jul 19 16:18:44 CDT 2000
> $Handle{$i}="OUT"."$i";
> $FileHandle=$Handle{$i};
> open($FileHandle, ">$Out.$i") || die "Can't open Outputfile $Out.$i :$!:\n";
> }
You'll need to use the "sym" generated, e.g.
my($HandleBase) = __PACKAGE.'::Handle'.Symbol::gensym();
my(%Handle);
foreach my $i (1..MAX-RECORDS) {
$Handle{$i} = \*{$HandleBase.$i};
}
This will happen at initialization. They you can use
the handles like:
open($Handle{$i}, ">$Out.$i") || die...;
> Can't use string ("OUT01") as a symbol ref while "strict refs" in use at
> ./DefMungeSplit.pl line 189 (#1)
That's because it isn't a ref. The \* makes it a glob ref, which
is an ancient artifact of perl.
I'm not sure where you're going with all this, but you may want to
look into IO::File. It's a cleaner way to manage files in many
cases.
Rob
More information about the Boulder-pm
mailing list