With the
Symbol module, you can use gensym() to create a new, anonymous typeglob. Since that's the customary way to get at a filehandle, you can do something like this, to create an array of anonymous filehandles:
#!/usr/bin/perl -w
use strict;
use Symbol;
my @handles;
for (1 .. 2) {
my $fh = gensym;
open $fh, "test$_";
push @handles, $fh;
}
foreach my $handle (@handles) {
print while (<$handle>);
print "---\n";
close $handle;
}
In a production environment, I wouldn't use a symbolic reference to a filename like I do in the first loop, but this is just an example.