Creating a random uniqie directory

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
Deke [ Mi, 13 Oktober 2004 05:33 ] [ ID #221786 ]

Re: Creating a random uniqie directory

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
John Bokma [ Mi, 13 Oktober 2004 05:39 ] [ ID #221787 ]

Re: Creating a random uniqie directory

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
jurgenex [ Mi, 13 Oktober 2004 07:06 ] [ ID #221789 ]

Re: Creating a random uniqie directory

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
John Bokma [ Mi, 13 Oktober 2004 05:39 ] [ ID #221854 ]

Re: Creating a random uniqie directory

[ Newsgroups trimmed ]


Deke <Deke [at] nospam.com> 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 [at] augustmail.com Perl programming
Fort Worth, Texas
Tad McClellan [ Mi, 13 Oktober 2004 06:15 ] [ ID #221856 ]

Re: Creating a random uniqie directory

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
jurgenex [ Mi, 13 Oktober 2004 07:06 ] [ ID #221857 ]

Re: Creating a random uniqie directory

"Jürgen Exner" <jurgenex [at] hotmail.com> 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
chris-usenet [ Mi, 13 Oktober 2004 14:10 ] [ ID #236589 ]

Re: Creating a random uniqie directory

"Jürgen Exner" <jurgenex [at] hotmail.com> 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
chris-usenet [ Mi, 13 Oktober 2004 14:10 ] [ ID #236591 ]

Re: Creating a random uniqie directory

chris-usenet [at] roaima.co.uk wrote:
> "Jürgen Exner" <jurgenex [at] hotmail.com> 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
jurgenex [ Mi, 13 Oktober 2004 14:53 ] [ ID #245664 ]

Re: Creating a random uniqie directory

chris-usenet [at] roaima.co.uk wrote:
> "Jürgen Exner" <jurgenex [at] hotmail.com> 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
jurgenex [ Mi, 13 Oktober 2004 14:53 ] [ ID #245673 ]

Re: Creating a random uniqie directory

Quoth "Jürgen Exner" <jurgenex [at] hotmail.com>:
> chris-usenet [at] roaima.co.uk wrote:
> > "Jürgen Exner" <jurgenex [at] hotmail.com> 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 [at] morrow.me.uk Frank Herbert, 'Dune'
Ben Morrow [ Mi, 13 Oktober 2004 22:27 ] [ ID #289185 ]

Re: Creating a random uniqie directory

Quoth "Jürgen Exner" <jurgenex [at] hotmail.com>:
> chris-usenet [at] roaima.co.uk wrote:
> > "Jürgen Exner" <jurgenex [at] hotmail.com> 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 [at] morrow.me.uk Frank Herbert, 'Dune'
Ben Morrow [ Mi, 13 Oktober 2004 22:27 ] [ ID #289195 ]

Re: Creating a random uniqie directory

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 [at] roaima.co.uk wrote:
>
>>"Jürgen Exner" <jurgenex [at] hotmail.com> 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
>
>
Jim Bunch [ Do, 14 Oktober 2004 06:29 ] [ ID #316178 ]

Re: Creating a random uniqie directory

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 [at] roaima.co.uk wrote:
>
>>"Jürgen Exner" <jurgenex [at] hotmail.com> 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
>
>
Jim Bunch [ Do, 14 Oktober 2004 06:29 ] [ ID #316191 ]
Perl » alt.perl » Creating a random uniqie directory

Vorheriges Thema: CHMOD script
Nächstes Thema: Fetching to and from and subject from MIME:Parser