Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Generating Random Filenames

by sh1tn (Priest)
on Apr 11, 2005 at 17:13 UTC ( [id://446686]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://446686]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 03:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found