Thanks all, I've now got enough info to solve the problem. Regards, Tim Bowden
On Sat, 2007-09-01 at 09:34 -0700, Tom Phoenix wrote: > On 9/1/07, Tim Bowden <[EMAIL PROTECTED]> wrote: > > > I'm writing a small cgi app that takes an uploaded file, stores it on > > disk and does some operations to it. To avoid multiple instances > > clobbering each other, I think I need to find a unique key to use in > > creating a dir specifically for use by that instance. Can anyone point > > me in the right direction here? > > You shouldn't be able to mkdir() with a directory name that already > exists, so it's possible to ensure a unique key with something like > this, using Unix filenames: > > my $temp_dir = "/tmp"; > my $start_time = time; > my $unique_key; > for (my $n = 0; "forever"; $n++) { > $unique_key = "unique$start_time$n"; > last if mkdir "$temp_dir/$unique_key", 0755; > die "mkdir '$temp_dir/$unique_key' failed: $!" if $n == 1000; > } > print "This program has created a directory named $unique_key.\n"; > > But for temporary files and directories, File::Temp already does the > heavy lifting: > > http://search.cpan.org/~tjenness/File-Temp-0.18/Temp.pm > > Hope this helps! > > --Tom Phoenix > Stonehenge Perl Training > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/