in reply to Generating Random Filenames

my $file_rand; do { $file_rand .= int rand(time) for 1..3 } while -e $file_rand;


Replies are listed 'Best First'.
Re^2: Generating Random Filenames
by Mugatu (Monk) on Apr 11, 2005 at 20:07 UTC
    This code creates a race condition. Between the time the -e test is run, and the file is open, that file could have been created. It would be better to use sysopen with appropriate flags (e.g. you can have it open for writing but fail if the file already exists), or even better to use File::Temp, which does that for you.