Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Update in perlop

0 views
Skip to first unread message

Balasundaram, Prateek

unread,
Sep 4, 2013, 8:19:17 AM9/4/13
to perlfaq...@perl.org
Hello all,

In the section: http://perldoc.perl.org/perlop.html#Auto-increment-and-Auto-decrement

I believe this line is incorrect:
"undef is always treated as numeric, and in particular is changed to 0 before incrementing (so that a post-increment of an undef value will return 0 rather than undef)."

Upon testing:
$ perl -le '$val=undef;print("Initial Value: $val");$val++;print("Incremented Value: $val");'
Initial Value:
Incremented Value: 1

It seems that the post-increment value of undef will be 1, not 0 as the documentation states.

Regards,
Prateek
--
Prateek Balasundaram
prateek.ba...@sig.com
(484)562-1281



________________________________

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Shlomi Fish

unread,
Sep 5, 2013, 1:40:19 AM9/5/13
to perlfaq...@perl.org
Hi Prateek,

On Wed, 4 Sep 2013 12:19:17 +0000
"Balasundaram, Prateek" <Prateek.Ba...@sig.com> wrote:

> Hello all,
>
> In the section:
> http://perldoc.perl.org/perlop.html#Auto-increment-and-Auto-decrement
>
> I believe this line is incorrect:
> "undef is always treated as numeric, and in particular is changed to 0 before
> incrementing (so that a post-increment of an undef value will return 0 rather
> than undef)."
>
> Upon testing:
> $ perl -le '$val=undef;print("Initial Value: $val");$val++;print("Incremented
> Value: $val");'
> Initial Value:
> Incremented Value: 1
>

What is meant by that is that if you do:

shlomif@telaviv1:~$ perl -le 'use Data::Dumper; $x=undef; my $y = ($x++);print
Dumper([$y])'
$VAR1 = [
0
];

shlomif@telaviv1:~$

Hope it helps.

Regards,

Shlomi Fish

> It seems that the post-increment value of undef will be 1, not 0 as the
> documentation states.
>
> Regards,
> Prateek
> --
> Prateek Balasundaram
> prateek.ba...@sig.com
> (484)562-1281
>

--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
List of Text Processing Tools - http://shlom.in/text-proc

Electrical Engineering studies. In the Technion. Been there. Done that. Forgot
a lot. Remember too much.

Please reply to list if it's a mailing list post - http://shlom.in/reply .
0 new messages