in reply to Re: File::Temp randomness when forking
in thread File::Temp randomness when forking

Your method will fail to generate a unique name if you are creating more than one file per process per second (which can happen easy enough), or even if you're on a system that does not handle PIDs sanely. File::Temp exists exactly because it is very easy to fall into this kind of trap and surprisingly hard to avoid all traps that come with temporary file generation. "Millions of systems the world over" do this badly and sometimes fail because their author did not consider all corner cases (especially since such errors tend to show up only on loaded production systems and not during testing). Using File::Temp for temporary files is definitely a best practice in my book and there would have to be very specific reasons for recommending against it.


Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan
  • Comment on Re^2: File::Temp randomness when forking

Replies are listed 'Best First'.
Re^3: File::Temp randomness when forking
by ryantate (Friar) on Nov 29, 2005 at 18:03 UTC
    File::Temp exists exactly because it is ... surprisingly hard to avoid all traps that come with temporary file generation.

    Thanks, this was my thinking precisely. I have some code I use to generate unique IDs using $$ and various other vars, which would have worked fine, but I figured it was about time I learn File::Temp. Also, I'm lazy ;->

A reply falls below the community's threshold of quality. You may see it by logging in.