in reply to Re: Automatically creating incremental file names
in thread Automatically creating incremental file names

Note you output two identical names: 1054051487.010345, not a good trait for making unique filenames. You're at the mercy of the platform's performance if you depend on timestamps alone. Combining the value with something else that's dynamic, such as a PID and/or a simple $counter++ is preferable, but still weak.

To really pick unique symbols, you should look for GUID or UUID generators, that's what they're for. A thousand machines running side by side won't even be able to pick the same symbol twice. Data::UUID seems useful.

If you want unique temporary filenames, please look for modules that do this. File::Temp for example. These often handle file cleanup too.

Simple timestamps, counters, and -e checks may introduce new race conditions only discovered when you try to scale up to a few hundred or thousand independent concurrent tasks. Don't reinvent the wheel, just to rediscover the limitations of a naive approach.

--
[ e d @ h a l l e y . c c ]

Replies are listed 'Best First'.
Re: Re: Re: Automatically creating incremental file names
by BrowserUk (Patriarch) on May 27, 2003 at 18:04 UTC

    Piffle!

    Addendum: The output shown, was not a list of names, but a list of times.

    Have you looked in File::Temp?

    Have you tried using it? Have you seen how slow and cumbersome it is?

    Have you seen the race conditions it creates?

    Have you seen the list of caveats and exclusions when used on systems other that *nix? Ie. VMS, Win32.

    ANY mechanism for determining unique file names that works by guessing a possible candidate, and then looking to see if it already exists, is doomed to failure in multi-processor and/or shared media environments.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller