Creating a random uniqie directory

Creating a random uniqie directory

am 13.10.2004 05:33:39 von Deke

I wanted to create a unique temporary directory for temporary processing
in Perl - since the perl script may be run by several processes at one
time by multiple users. Will someone suggest some efficient CPAN or
builtin function or code for that?

Thanks

Re: Creating a random uniqie directory

am 13.10.2004 05:39:49 von John Bokma

Deke wrote:

> I wanted to create a unique temporary directory for temporary processing
> in Perl - since the perl script may be run by several processes at one
> time by multiple users. Will someone suggest some efficient CPAN or
> builtin function or code for that?

Are "random" named temp files not sufficient enough?

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html

Re: Creating a random uniqie directory

am 13.10.2004 05:39:49 von John Bokma

Deke wrote:

> I wanted to create a unique temporary directory for temporary processing
> in Perl - since the perl script may be run by several processes at one
> time by multiple users. Will someone suggest some efficient CPAN or
> builtin function or code for that?

Are "random" named temp files not sufficient enough?

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html

Re: Creating a random uniqie directory

am 13.10.2004 06:15:56 von Tad McClellan

[ Newsgroups trimmed ]


Deke wrote:

> I wanted to create a unique temporary directory
^^^^^^^^^

> Will someone suggest some efficient CPAN or
> builtin function or code for that?


I will suggest that you check the Perl FAQ *before* posting
to the Perl newsgroup.


perldoc -q temporary

How do I make a temporary file name?


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Re: Creating a random uniqie directory

am 13.10.2004 07:06:35 von jurgenex

Deke wrote:
> I wanted to create a unique temporary directory for temporary
> processing in Perl - since the perl script may be run by several
> processes at one time by multiple users. Will someone suggest some
> efficient CPAN or builtin function or code for that?

Please see "perldoc -q temp":
"How do I make a temporary file name?"

Using that name to create a directory instead of a plain file is left as an
exercise.

jue

Re: Creating a random uniqie directory

am 13.10.2004 07:06:35 von jurgenex

Deke wrote:
> I wanted to create a unique temporary directory for temporary
> processing in Perl - since the perl script may be run by several
> processes at one time by multiple users. Will someone suggest some
> efficient CPAN or builtin function or code for that?

Please see "perldoc -q temp":
"How do I make a temporary file name?"

Using that name to create a directory instead of a plain file is left as an
exercise.

jue

Re: Creating a random uniqie directory

am 13.10.2004 14:10:28 von chris-usenet

"Jürgen Exner" wrote:
> Please see "perldoc -q temp":

I'd argue that the determination of $temp_dir in that section's example
is wrong. Normal *IX approaches imply that $TMPDIR should override the use
of /tmp, whereas the example only considers $TMPDIR if /tmp doesn't exist.

Is this a documentation "fault" and if so, is posting here sufficient?
Chris

Re: Creating a random uniqie directory

am 13.10.2004 14:10:28 von chris-usenet

"Jürgen Exner" wrote:
> Please see "perldoc -q temp":

I'd argue that the determination of $temp_dir in that section's example
is wrong. Normal *IX approaches imply that $TMPDIR should override the use
of /tmp, whereas the example only considers $TMPDIR if /tmp doesn't exist.

Is this a documentation "fault" and if so, is posting here sufficient?
Chris

Re: Creating a random uniqie directory

am 13.10.2004 14:53:57 von jurgenex

chris-usenet@roaima.co.uk wrote:
> "Jürgen Exner" wrote:
>> Please see "perldoc -q temp":
>
> I'd argue that the determination of $temp_dir in that section's
> example is wrong. Normal *IX approaches imply that $TMPDIR should
> override the use of /tmp, whereas the example only considers $TMPDIR
> if /tmp doesn't exist.

Good catch! I agree, the way $temp_dir is determined
my $temp_dir = -d '/tmp' ? '/tmp' : $ENV{TMP} || $ENV{TEMP};
does not behave as most people would expect.

> Is this a documentation "fault" and if so, is posting here sufficient?

See "perldoc perlbug". You found it, the honors are yours.

jue

Re: Creating a random uniqie directory

am 13.10.2004 14:53:57 von jurgenex

chris-usenet@roaima.co.uk wrote:
> "Jürgen Exner" wrote:
>> Please see "perldoc -q temp":
>
> I'd argue that the determination of $temp_dir in that section's
> example is wrong. Normal *IX approaches imply that $TMPDIR should
> override the use of /tmp, whereas the example only considers $TMPDIR
> if /tmp doesn't exist.

Good catch! I agree, the way $temp_dir is determined
my $temp_dir = -d '/tmp' ? '/tmp' : $ENV{TMP} || $ENV{TEMP};
does not behave as most people would expect.

> Is this a documentation "fault" and if so, is posting here sufficient?

See "perldoc perlbug". You found it, the honors are yours.

jue

Re: Creating a random uniqie directory

am 13.10.2004 22:27:11 von Ben Morrow

Quoth "Jürgen Exner" :
> chris-usenet@roaima.co.uk wrote:
> > "Jürgen Exner" wrote:
> >> Please see "perldoc -q temp":
> >
> > I'd argue that the determination of $temp_dir in that section's
> > example is wrong. Normal *IX approaches imply that $TMPDIR should
> > override the use of /tmp, whereas the example only considers $TMPDIR
> > if /tmp doesn't exist.
>
> Good catch! I agree, the way $temp_dir is determined
> my $temp_dir = -d '/tmp' ? '/tmp' : $ENV{TMP} || $ENV{TEMP};
> does not behave as most people would expect.

....which is yet another reason to use File::Temp :).

Ben

--
I must not fear. Fear is the mind-killer. I will face my fear and
I will let it pass through me. When the fear is gone there will be
nothing. Only I will remain.
ben@morrow.me.uk Frank Herbert, 'Dune'

Re: Creating a random uniqie directory

am 13.10.2004 22:27:11 von Ben Morrow

Quoth "Jürgen Exner" :
> chris-usenet@roaima.co.uk wrote:
> > "Jürgen Exner" wrote:
> >> Please see "perldoc -q temp":
> >
> > I'd argue that the determination of $temp_dir in that section's
> > example is wrong. Normal *IX approaches imply that $TMPDIR should
> > override the use of /tmp, whereas the example only considers $TMPDIR
> > if /tmp doesn't exist.
>
> Good catch! I agree, the way $temp_dir is determined
> my $temp_dir = -d '/tmp' ? '/tmp' : $ENV{TMP} || $ENV{TEMP};
> does not behave as most people would expect.

....which is yet another reason to use File::Temp :).

Ben

--
I must not fear. Fear is the mind-killer. I will face my fear and
I will let it pass through me. When the fear is gone there will be
nothing. Only I will remain.
ben@morrow.me.uk Frank Herbert, 'Dune'

Re: Creating a random uniqie directory

am 14.10.2004 06:29:26 von Jim Bunch

here's a snipit that creates a random directory:

#!/usr/bin/perl

TRYAGAIN:
$tmpdir=sprintf("Job%5.5d",rand(99999));

if( ! -e $tmpdir ){ mkdir($tmpdir,0755) }
else { go to TRYAGAIN };
print "Created directory: $tmpdir\n";

Jim

Jürgen Exner wrote:
> chris-usenet@roaima.co.uk wrote:
>
>>"Jürgen Exner" wrote:
>>
>>>Please see "perldoc -q temp":
>>
>>I'd argue that the determination of $temp_dir in that section's
>>example is wrong. Normal *IX approaches imply that $TMPDIR should
>>override the use of /tmp, whereas the example only considers $TMPDIR
>>if /tmp doesn't exist.
>
>
> Good catch! I agree, the way $temp_dir is determined
> my $temp_dir = -d '/tmp' ? '/tmp' : $ENV{TMP} || $ENV{TEMP};
> does not behave as most people would expect.
>
>
>>Is this a documentation "fault" and if so, is posting here sufficient?
>
>
> See "perldoc perlbug". You found it, the honors are yours.
>
> jue
>
>

Re: Creating a random uniqie directory

am 14.10.2004 06:29:26 von Jim Bunch

here's a snipit that creates a random directory:

#!/usr/bin/perl

TRYAGAIN:
$tmpdir=sprintf("Job%5.5d",rand(99999));

if( ! -e $tmpdir ){ mkdir($tmpdir,0755) }
else { go to TRYAGAIN };
print "Created directory: $tmpdir\n";

Jim

Jürgen Exner wrote:
> chris-usenet@roaima.co.uk wrote:
>
>>"Jürgen Exner" wrote:
>>
>>>Please see "perldoc -q temp":
>>
>>I'd argue that the determination of $temp_dir in that section's
>>example is wrong. Normal *IX approaches imply that $TMPDIR should
>>override the use of /tmp, whereas the example only considers $TMPDIR
>>if /tmp doesn't exist.
>
>
> Good catch! I agree, the way $temp_dir is determined
> my $temp_dir = -d '/tmp' ? '/tmp' : $ENV{TMP} || $ENV{TEMP};
> does not behave as most people would expect.
>
>
>>Is this a documentation "fault" and if so, is posting here sufficient?
>
>
> See "perldoc perlbug". You found it, the honors are yours.
>
> jue
>
>