in reply to Filenames based on timestamp

you could use the time that you've got available, then increment a counter at the end of the filename.
my $time = time(); my $counter = 0; while(-e "$time_$counter") { $counter++; } open(F, ">$time_$counter") or die "blah blah $!";
that way you get unique filenames that have a timestamp in them, they just have an extra number at the end.

Replies are listed 'Best First'.
Re^2: Filenames based on timestamp
by Aristotle (Chancellor) on Jun 27, 2002 at 17:02 UTC
    This is prone to race conditions when several processes are involved. Between the -e test and the actual file creation, a file of the name in question may have been created by another process.

    Makeshifts last the longest.

      that's true. you could work around that by also included a PID in the filename.
      while(-e "$time_$$_$counter") { $counter++; } open(F, ">$time_$$_$counter");
      of course, then the filenames won't necessarily be in ascending order chronologically.
        what about multiple threads :-)

        page 572-574 of camel3 suggests something along the lines of...
        $fn = "filename_20020723141223_"; my $c = 1; do { $fn .= "$c"; $c++; } until sysopen(FH, $fn, O_RDWR | O_CREAT | O_EXCL, 0600); # now do I/O using $fh handle...