You could try the File::Temp module. Or if you really want to generate your own filenames:
#!/usr/bin/perl
use strict;
use warnings;
for (my $i = 1; $i < 10; $i++)
{
my $filename = time . rand;
print "$filename\n";
open FILE, ">$filename";
print FILE "BOOGA BOOGA $i\n";
close FILE;
}
# If that's not unique enough, try this:
for (my $i = 1; $i < 10; $i++)
{
my $filename = time() . rand() . rand();
print "$filename\n";
open FILE, ">$filename";
print FILE "BOOGA BOOGA 2 x $i\n";
close FILE;
}
__END__
This works as long as you read the files in directory order, and don't sort them by name. The first file created is the first in directory order, and so on for all the files. So it actually doesn't matter that the names aren't in ASCII order, as long as you don't sort them.
Update: here's some code to test that the files do come out in the same order as they were created:
#!/usr/bin/perl
use strict;
use warnings;
opendir DIR, ".";
# files starting with 10 should be okay for a while
my @files = grep{/^10/} readdir(DIR);
closedir DIR;
for my $file(@files)
{
open FILE, "<$file" or die "can't open $file: $!";
local $/ = undef;
my $data = <FILE>;
close FILE;
chomp $data;
print "$data\n";
}
__END__