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
Received on 06/01/07
This archive was generated by hypermail 2.2.0 : 12/19/08 EST