Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^2: Unique filenames with Time::HiRes

by AcidHawk (Vicar)
on Jul 19, 2004 at 08:08 UTC ( #375480=note: print w/replies, xml ) Need Help??

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

The filenames are created using a command line script that accepts parameters and builds the file. I need to keep the counter number somewhere else and not in the script itself.

If I dont lock the 'counter number holder file thingy' and two occurances of the cli access the 'counter number holder file thingy', each occurance of the script will get the same number.. hence the requirement to lock the 'counter number holder file thingy'.

I do agree though that I might need to look at a database.

Of all the things I've lost in my life, its my mind I miss the most.
  • Comment on Re^2: Unique filenames with Time::HiRes

Replies are listed 'Best First'.
Re^3: Unique filenames with Time::HiRes
by bsb (Priest) on Jul 19, 2004 at 08:16 UTC
    Maybe just append a random number, lock it successfully, or try another.
      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...

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2021-01-19 18:45 GMT
Find Nodes?
    Voting Booth?