[32854] in Perl-Users-Digest
Perl-Users Digest, Issue: 4120 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 20 09:09:32 2014
Date: Mon, 20 Jan 2014 06:09:02 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 20 Jan 2014 Volume: 11 Number: 4120
Today's topics:
Re: Please explain "and next" <rweikusat@mobileactivedefense.com>
Re: Please explain "and next" <bjoern@hoehrmann.de>
Re: Please explain "and next" <rweikusat@mobileactivedefense.com>
Re: Please explain "and next" <dave@invalid.invalid>
Re: Please explain "and next" <gravitalsun@hotmail.foo>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 19 Jan 2014 18:29:11 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Please explain "and next"
Message-Id: <87d2jnhll4.fsf@sable.mobileactivedefense.com>
"Dave Saville" <dave@invalid.invalid> writes:
> Came across this today
>
> print "1 OK\n" and next unless (length $line[0]);
>
> Never seen that construct before. Is it just some perlish shorthand
> to get stuff on one line?
In this case, it's just a verbose and somewhat byzantine way to express
print("1 OK\n), next unless length($line[0]);
Generally, the so-called 'logical operators', (||, &&, //, and, or)
don't evaluate their right-hand arguments if the value of the combined
expression is already known after evaluating the left-hand
argument. This implies they can be used for flow-control in the sense
that code making up the right-hand argument will only be executed when
executeing the code of the left-hand argument wasn't sufficient to
determine the result of the expression. The line you quoted is a bad
example because the 'next' isn't really executed conditionally because
the print-statement always returns true. A better example could be
something like
$age >= 18 or die("Won't sell this to you.");
------------------------------
Date: Sun, 19 Jan 2014 19:45:43 +0100
From: Bjoern Hoehrmann <bjoern@hoehrmann.de>
Subject: Re: Please explain "and next"
Message-Id: <n47od95adr56es5340jrhg6af5ct86os85@hive.bjoern.hoehrmann.de>
* Rainer Weikusat wrote in comp.lang.perl.misc:
>"Dave Saville" <dave@invalid.invalid> writes:
>> Came across this today
>>
>> print "1 OK\n" and next unless (length $line[0]);
>>
>> Never seen that construct before. Is it just some perlish shorthand
>> to get stuff on one line?
>
>In this case, it's just a verbose and somewhat byzantine way to express
>
>print("1 OK\n), next unless length($line[0]);
>The line you quoted is a bad example because the 'next' isn't really
>executed conditionally because the print-statement always returns true.
>A better example could be something like
>
> $age >= 18 or die("Won't sell this to you.");
Actually, `print` returns a true value only if successful and it might
have failed for any number of reasons, like a closed socket, a full hard
disk, and other IO problems like that.
--
Bjrn Hhrmann mailto:bjoern@hoehrmann.de http://bjoern.hoehrmann.de
Am Badedeich 7 Telefon: +49(0)160/4415681 http://www.bjoernsworld.de
25899 Dagebll PGP Pub. KeyID: 0xA4357E78 http://www.websitedev.de/
------------------------------
Date: Sun, 19 Jan 2014 18:48:18 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Please explain "and next"
Message-Id: <878uubhkp9.fsf@sable.mobileactivedefense.com>
Bjoern Hoehrmann <bjoern@hoehrmann.de> writes:
> * Rainer Weikusat wrote in comp.lang.perl.misc:
>>"Dave Saville" <dave@invalid.invalid> writes:
>>> Came across this today
>>>
>>> print "1 OK\n" and next unless (length $line[0]);
>>>
>>> Never seen that construct before. Is it just some perlish shorthand
>>> to get stuff on one line?
>>
>>In this case, it's just a verbose and somewhat byzantine way to express
>>
>>print("1 OK\n), next unless length($line[0]);
>
>>The line you quoted is a bad example because the 'next' isn't really
>>executed conditionally because the print-statement always returns true.
>>A better example could be something like
>>
>> $age >= 18 or die("Won't sell this to you.");
>
> Actually, `print` returns a true value only if successful and it might
> have failed for any number of reasons, like a closed socket, a full hard
> disk, and other IO problems like that.
But that's exceedingly unlikely because print just copies the output
data into an internal buffer and I doubt that the intention behind the
original code was to continue execution when print failed.
------------------------------
Date: Sun, 19 Jan 2014 18:55:00 +0000 (UTC)
From: "Dave Saville" <dave@invalid.invalid>
Subject: Re: Please explain "and next"
Message-Id: <fV45K0OBJxbE-pn2-cvX4F9dO3SDN@paddington.bear.den>
Thanks all.
--
Regards
Dave Saville
------------------------------
Date: Sun, 19 Jan 2014 23:51:59 +0200
From: George Mpouras <gravitalsun@hotmail.foo>
Subject: Re: Please explain "and next"
Message-Id: <lbhhe7$ql5$1@news.ntua.gr>
Στις 19/1/2014 17:02, ο/η Dave Saville έγραψε:
> print "1 OK\n" and next unless (length $line[0]);
use strict;
use warnings;
while (<DATA>) {
chomp;
my @line = split /,/;
print "1 OK\n" and next unless (length $line[0]);
print "id $line[1]\n";
}
__DATA__
,id00
aaaaaaaaaa,id01
bbbbbbbbb,id02
cccccccc,id03
,id04
,id05
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 4120
***************************************