use Time::HiRes qw(gettimeofday); use POSIX qw(strftime); my $ArchiveDir = "/tmp/archive/"; ( -w $ArchiveDir ) or die "archive dir $ArchiveDir not writable"; # Get the number of microseconds. (undef, $usec) = gettimeofday; # Now create the archive filename and open that file. Use # sub-second resolution for name to make sure it's unique. $ArchiveFile = strftime "%Y%m%d%H%M%S", localtime; # make sure we get the full 6 digits on microseconds. $ArchiveFile .= "." . sprintf("%06d",$usec); # Combine $ArchiveDir with the filename. $ArchiveFile = $ArchiveDir . $ArchiveFile; # open the file. open(ArchiveFH,">$ArchiveFile") or die "failed to open ArchiveFile: $!";