On Thu, 13 Sep 2001, John Tobey wrote:
> Variables declared "my" are not part of any typeglob.
>
> I'm not sure what you want to do, associate an open filehandle with
> each of a large number of arrays? Maybe a hash of structures or two
> parallel hashes or arrays are a better solution than something based
> on globs.
Basically, I wanted a one-stop solution for generating a set of mixed
files, without having to do a lot of code maint.
I currently have a program which wakes up based on a file being recieved,
and needs to parse it out of it's current format into another format,
which gets spit out in multiple files.
In the code (follows) I wanted to have a filehandle doc, which wrote a
file called doc, which referenced an array called @doc. That way, life is
as easy as updating the parser definitions (if, for example, I want a new
file type), and the file creation / mapping works like magic.
So, I want the list entry in @f to cascade down through -- entry doc
refers to the FH doc, @doc, etc...
Here is the actual piece of code that I wrote:
@f = qw(doc trx mtr act cus trl org);
@refs = map {
$filestr = join("_", ($_, $date, $time, $doc_id));
open($_, " > $path/gaa_$filestr") or die "Unable to open
gaa_$filestr: $!\n";
\*{$_};
} @f;
foreach (@refs) {
print $_ join("~", @$_)."\n" unless (ref($$_[0]) =~ /ARRAY/);
print $_ join("\n", map { join("~", @$_ ) } @$_) if (ref($$_[0] =~
/ARRAY/);
close($_);
}