RE: [Nolug] Perl Question

From: John Souvestre <johns_at_sstar.com>
Date: Fri, 1 Jun 2007 12:27:57 -0500
Message-ID: <008401c7a472$3231f3f0$0a01010a@JohnS>

H Friedrich.

 

OK. Now I understand. :-)

 

Thanks much!

John

    John Souvestre - Southern Star - (504) 888-3348 - www.sstar.com

  _____

From: owner-nolug@redfishnetworks.com [mailto:owner-nolug@redfishnetworks.com]
On Behalf Of Friedrich Gurtler
Sent: Friday, June 01, 2007 10:45 AM
To: nolug@nolug.org
Subject: Re: [Nolug] Perl Question

 

Compare to:

print "this is will not print" if 0;
print "this is will print" unless 0;

When you say a "do-while" loop, you imply that the condition is evaluated after
the loop is run, like Katrina said.
When you say a "while" loop, you mean the condition is evaluated, then the loop
is run.

Perl lets you place conditionals after statements because Larry Wall thinks it
reads more easily. The while construct after a statement is a 'while' loop, not
'do-while' loop. It is evaluated, and then the loop is run possibly run
followed by another evaluated, etc.

Its just syntactic sugar.

On 6/1/07, John Souvestre <johns@sstar.com> wrote:

Hello Friedrich.

 

I think that they question is would happens in:

 

    print "will I print once or forever" while (1);

It seems to print forever, thus an implied "do" at the beginning of the line.
???

 

Thanks,

John

    John Souvestre - Southern Star - (504) 888-3348 - www.sstar.com

  _____

From: owner-nolug@redfishnetworks.com [mailto:owner-nolug@redfishnetworks.com]
On Behalf Of Friedrich Gurtler
Sent: Friday, June 01, 2007 10:17 AM

To: nolug@nolug.org
Subject: Re: [Nolug] Perl Question

 

It cant.

do {
    print "Do while runs code once even though condition is false. This will
print once";
} while (0);

while(0)
{
    print "While loops do not, this wont print";
}

print "while at the end of statement is a while, not a do-while loop" while (0);

On 6/1/07, John Souvestre < johns@sstar.com <mailto:johns@sstar.com> > wrote:

Hi Katrina.I

I understand what you are saying. I was just unaware that the "do while" loop
could be written without actually having a "do". :)

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 Katrina Niolet
Sent: Friday, June 01, 2007 9:00 AM
To: nolug@nolug.org
Subject: Re: [Nolug] Perl Question

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 <mailto:nolug@nolug.org>
> >
> > ___________________
> > Nolug mailing list
> > nolug@nolug.org

___________________
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