Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: Unique filenames with Time::HiRes

by bsb (Priest)
on Jul 19, 2004 at 08:16 UTC ( [id://375484]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Unique filenames with Time::HiRes
in thread Unique filenames with Time::HiRes

Maybe just append a random number, lock it successfully, or try another.
  • Comment on Re^3: Unique filenames with Time::HiRes

Replies are listed 'Best First'.
Re^4: Unique filenames with Time::HiRes
by grinder (Bishop) on Jul 19, 2004 at 08:27 UTC
    Maybe just append a random number

    Or maybe not.

    The OP states that the names must be in sequence. Consider two files created in the epoch second 1090225457. The first file is generated with the rand string 0.837 (rounded). Half a second later, still in the same epoch second, another file is created, and rand returns 0.238 (rounded). The second file will sort before the first...

    The same critism can be made of beable's solution elsewhere in this thread.

    - another intruder with the mooring of the heat of the Perl

      Granted. Although I'm not sure that one of the other being "first" makes much sense at that granularity, although it'll depend on the problem.

      I guess I'm more suspicious of the OP's conception of the problem and the need for "independent" processes to syncronize in this way. Seems like there'd be a better solution than sequentially naming files but there wasn't enough detail to judge.

      Sure, you can make that criticism. But if you think about it, when you read the files in directory order, as long as you don't sort the files, you'll get them in the order they were created. Therefore, appending a random number is a perfectly acceptable method of generating the unique file names. Except for the small possibility of getting the same filename...
        when you read the files in directory order, as long as you don't sort the files, you'll get them in the order they were created.

        I think you're making a huge assumption there about the filesystem. perldoc -f readdir and man 3 readdir say nothing about the order of the directory entries they give you.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-18 20:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found