in reply to Unique filehandle -- what is correct?

use Time::HiRes 'gettimeofday'; use Digest::MD5 'md5_hex'; use strict; use warnings; my $file = uc md5_hex(join ' ', gettimeofday, rand); print $file;
EDIT: Crap, forgot to put in code tags before.

Replies are listed 'Best First'.
Re^2: Unique filehandle -- what is correct?
by JavaFan (Canon) on Dec 11, 2011 at 15:58 UTC
    If you don't want to use a module, please advice the OP to use something that's trivially unique. No two processes can have the same process id, so instead of just hoping the combination of gettimeofday and rand is unique, just use $$. It will be unique and doesn't need your five functions to return a file name.
      It is virtually impossible for two separate users to trigger on both the same microsecond and rand value. Specifically, on the order of billions to one or more. But I suppose PID would work too now that you mention it.

      Yeah. And the PID can easily been guessed or searched for by an attacker. Using the PID as template for temporary file names is a classic way to open a program for security exploits.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        Where does "attacker" come into it? That's not mentioned at all by the OP. Of course, if you have an attacker on your webserver that's able to write files, you're likely to be in deep shit anyway.

        But feel free to add to add as many random numbers as you want to your pid so you no longer have to bother about this attacker that has gained access to your system.

        Now excuse me, I have to hide that box of chocolates under my car seat, lest someone breaking in my car gets easy access to my stash.