[33077] in Perl-Users-Digest
Perl-Users Digest, Issue: 4353 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 21 16:09:17 2015
Date: Wed, 21 Jan 2015 13:09:03 -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 Wed, 21 Jan 2015 Volume: 11 Number: 4353
Today's topics:
Re: What is ++ operation <kst-u@mib.org>
Re: What is ++ operation <rweikusat@mobileactivedefense.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 21 Jan 2015 11:48:03 -0800
From: Keith Thompson <kst-u@mib.org>
Subject: Re: What is ++ operation
Message-Id: <ln7fwfq5jg.fsf@nuthaus.mib.org>
Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
> Owen <xemoth@gmail.com> writes:
>> On Friday, January 16, 2015 at 3:09:52 PM UTC+11, Paul Gekakis wrote:
>>> thanks
>>
>> Try by experiment, here's a variation;
>>
>> ===============================
>>
>> #!/usr/bin/perl
>>
>> use strict;
>>
>> my $letter = "a";
>>
>> foreach (1 .. 26){
>> print "$letter\n";
>> $letter++;
>> }
>>
>> ==============================
>
> While that's surely "what every one else does", it's IMHO a bad
> example. The postincrement (and -decrement) operators have very
> peculiar semantics, namely 'modify the value but return the previous
> value. Unless that's specifically what's intended, eg, as a bad example,
>
> perl -e 'my $l = "a"; print $l++,"\n" for 1 .. 26'
>
> one should consider using the simpler preincrement (or -decrement)
> operator instead (returning the new value).
But if the value is discarded, as it is in this example, pre-increment
and post-increment are effectively identical.
There's a big difference between these:
$c = $letter++;
vs.
$c = ++$letter;
but these are effectively identical:
$letter++;
vs.
++$letter;
Personally, if I see or use a ++ or -- operator in a context where the
result is discarded, I don't even bother to think about the result.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
------------------------------
Date: Wed, 21 Jan 2015 20:35:34 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: What is ++ operation
Message-Id: <87ppa7lvmx.fsf@doppelsaurus.mobileactivedefense.com>
Keith Thompson <kst-u@mib.org> writes:
> Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
>> Owen <xemoth@gmail.com> writes:
>>> On Friday, January 16, 2015 at 3:09:52 PM UTC+11, Paul Gekakis wrote:
>>>> thanks
>>>
>>> Try by experiment, here's a variation;
>>>
>>> ===============================
>>>
>>> #!/usr/bin/perl
>>>
>>> use strict;
>>>
>>> my $letter = "a";
>>>
>>> foreach (1 .. 26){
>>> print "$letter\n";
>>> $letter++;
>>> }
>>>
>>> ==============================
>>
>> While that's surely "what every one else does", it's IMHO a bad
>> example. The postincrement (and -decrement) operators have very
>> peculiar semantics, namely 'modify the value but return the previous
>> value. Unless that's specifically what's intended, eg, as a bad example,
>>
>> perl -e 'my $l = "a"; print $l++,"\n" for 1 .. 26'
>>
>> one should consider using the simpler preincrement (or -decrement)
>> operator instead (returning the new value).
>
> But if the value is discarded, as it is in this example, pre-increment
> and post-increment are effectively identical.
Surely, but if the result is discarded, anyway, what's the point in
using an operator preserving the old value?
------------------------------
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 4353
***************************************