Re: [Nolug] Perl Question

From: B. Estrade <estrabd_at_gmail.com>
Date: Fri, 1 Jun 2007 14:26:41 +0000
Message-ID: <a7ee76680706010726j722df90amaf5f337513bb6155@mail.gmail.com>

I do not know how you are initializing things, but you should give
your script a fighting chance of getting a unique file name on the
first or second try.

Initialize the name with an MD5 hash (Digest::MD5) of the { unix time
(Time::Local) appended with a single rand(255) } ... Both modules are
included as "core" modules by default. I'd also put that in the "do"
block using the first construct below.

Lastly, if using srand to salt the rand number generator, call it no
more than once per script - especially not without a unique argument
each time. See http://perldoc.perl.org/functions/srand.html .

Cheers.

On 6/1/07, Katrina Niolet <kniolet@ildiinc.com> wrote:
> the difference between:
>
> do {
> code
> } while (condition);
>
> and
>
> while(condition) {
> code
> }
>
> is that in the first it will always happen at least once because the condition
> is post-tested; in the second its pre-tested, so if the condition is false
> the block will never execute.
>
> Le Friday 01 June 2007 08:48:39 Friedrich Gurtler, vous avez écrit:
> > Its not skipping the 'do' in the 'do while' loop, its just a 'while' loop,
> > ala C, C++, Java, C# etc.
> >
> > If you wanted to perl-ify it (for no reason), you could do something like
> >
> > $filename .= rand(10) while ((-f "$filename.tmp") || (-f "$filename.sub"));
> >
> > Supposedly thats easier to read, but I don't really get it. Hope this
> > helps.
> >
> > -- Fritz
> >
> > On 6/1/07, John Souvestre <johns@sstar.com> wrote:
> > > Hi Ray.
> > >
> > > Thanks! I did some reading and did find the -f function. But I didn't
> > > see
> > > anything about skipping the "do" in the "do while" loop. Can that be
> > > done with
> > > other constructs, too?
> > >
> > > Thanks,
> > >
> > > John
> > >
> > > John Souvestre - Southern Star - (504) 888-3348 - www.sstar.com
> > >
> > > -----Original Message-----
> > > From: owner-nolug@redfishnetworks.com [mailto:
> > > owner-nolug@redfishnetworks.com]
> > > On Behalf Of -ray
> > > Sent: Friday, June 01, 2007 12:12 AM
> > > To: nolug@nolug.org
> > > Subject: Re: [Nolug] Perl Question
> > >
> > >
> > > Yep, that's what it's doing. -f is a function that returns true if the
> > > file exists (see man perlfunc). It's just a "do while" loop, that keeps
> > > appending a random digit to the filename until you get a filename that's
> > > not in use.
> > >
> > > while ((-f "$filename.tmp") || (-f "$filename.sub")) {
> > > $filename .= rand(10);
> > > }
> > >
> > > ray
> > >
> > > On Thu, 31 May 2007, John Souvestre wrote:
> > > > Hi.
> > > >
> > > > I'm trying to figure out a Perl script. One line in it has me baffled.
> > > >
> > > > I believe it is intended to extend a filename till it is unique. But I
> > >
> > > don't
> > >
> > > > quite grasp the syntax.
> > > >
> > > > $filename .= rand(10) while (-f "$filename.tmp") || (-f
> > >
> > > "$filename.sub");
> > >
> > > > Is this a shorthand way of writing a "do while" loop?
> > > >
> > > > And what does the "-f" do?
> > > >
> > > > Thanks!
> > > >
> > > > John
> > > >
> > > > John Souvestre - Southern Star - (504) 888-3348 - www.sstar.com
> > > >
> > > >
> > > > ___________________
> > > > Nolug mailing list
> > > > nolug@nolug.org
> > >
> > > --
> > > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> > > Ray DeJean http://www.r-a-y.org
> > > Systems Engineer Southeastern Louisiana University
> > > IBM Certified Specialist AIX Administration, AIX Support
> > > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> > >
> > > ___________________
> > > Nolug mailing list
> > > nolug@nolug.org
> > >
> > > ___________________
> > > Nolug mailing list
> > > nolug@nolug.org
>
>
> ___________________
> Nolug mailing list
> nolug@nolug.org
>

-- 
225.578.1920
AIM: bz743
http://www.loni.org/
estrabd@lsu.edu
estrabd@gmail.com
___________________
Nolug mailing list
nolug@nolug.org
Received on 06/01/07

This archive was generated by hypermail 2.2.0 : 12/19/08 EST