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__
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.