NodeReaper has asked for the wisdom of the Perl Monks concerning the following question:

Replies are listed 'Best First'.
Re: create randomize file name
by jmcnamara (Monsignor) on Feb 05, 2003 at 09:54 UTC

    The question isn't clear so I'm just guessing at what might be helpful.

    The POSIX function tmpnam() will give you a random filename that you can use to create a temporary file (race conditions notwithstanding):

    #!/usr/bin/perl -w use strict; use POSIX 'tmpnam'; print tmpnam(), "\n";

    Alternatively, you could use File::Temp, which is core in more recent versions of perl. This will provide you with a named or unnamed filehandle without the race condition worries. It supports several flavours of temp file creation including one that allows a template to be included in the filename:

    use File::Temp ':mktemp'; my ($fh, $filename) = mkstemp( "filename.XXXX" ); print $filename, "\n";

    --
    John.