Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re^3: Generate a unique ID

by happy.barney (Friar)
on Nov 16, 2010 at 08:09 UTC ( #871655=note: print w/replies, xml ) Need Help??

in reply to Re^2: Generate a unique ID
in thread Generate a unique ID

use -X
unless (mkdir $dir) { -d $dir && ... dir exists; -w _ || ... not writable by euid -x _ || ... not traversable by euid }
if you look for atomic test, you can also open files with O_CREAT | O_EXCL. Then, you can just use pid + start time + local counter
$fh = IO::File->new ($filename, O_EXCL | O_CREAT | ...)

Replies are listed 'Best First'.
Re^4: Generate a unique ID
by BrowserUk (Pope) on Nov 16, 2010 at 08:16 UTC
    use -X

    -X uses stat and that takes quite a long time, especially on Win32. It leaves the possibility that between your failed attempt and the return of the test, another program (or another copy of this program), will get in and create the directory.

    But as javafan pointed out, that isn't necessary. $! tells me the reason for failure. See Re^4: Generate a unique ID.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://871655]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2018-04-21 00:34 GMT
Find Nodes?
    Voting Booth?