Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Unique filenames with Time::HiRes

by beable (Friar)
on Jul 19, 2004 at 07:59 UTC ( [id://375479]=note: print w/replies, xml ) Need Help??


in reply to Unique filenames with Time::HiRes

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__

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://375479]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-19 22:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found