Barry Brevik wrote: > Hello- > >>From time to time I need a subroutine to generate a temporary file name > so I created an imperfect routine (shown below) to generate a file name > based on the current time. The problem with this is that it will create > only 1 'unique' name every second, and when the day rolls over, it will > start duplicating those supposedly unique file names. > > None of this has been an issue in the past, but now it is, so I'm asking > if any of you have a better, more unique, algorithm equal to the task. > If it is not guaranteed to be unique, it is OK if I have to call it 4 or > 5 times until I get a unique file name.
Did you need to roll your own or would File::Temp do? It works ok for me.
File::Temp(3) User Contributed
Perl Documentation File::Temp(3)
NAME
File::Temp - return name and handle of a temporary file safely
SYNOPSIS
use File::Temp qw/ tempfile tempdir /;
$fh = tempfile();
($fh, $filename) = tempfile();
($fh, $filename) = tempfile( $template, DIR => $dir);
($fh, $filename) = tempfile( $template, SUFFIX => '.dat');
($fh, $filename) = tempfile( $template, TMPDIR => 1 );
binmode( $fh, ":utf8" );
$dir = tempdir( CLEANUP => 1 );
($fh, $filename) = tempfile( DIR => $dir );
Object interface:
require File::Temp;
use File::Temp ();
use File::Temp qw/ :seekable /;
$fh = File::Temp->new();
$fname = $fh->filename;
$fh = File::Temp->new(TEMPLATE => $template);
$fname = $fh->filename;
$tmp = File::Temp->new( UNLINK => 0, SUFFIX => '.dat' );
print $tmp "Some data\n";
print "Filename is $tmp\n";
$tmp->seek( 0, SEEK_END );
smime.p7s
Description: S/MIME Cryptographic Signature
_______________________________________________ Perl-Win32-Users mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
