develooper Front page | perl.perl5.porters | Postings from May 2003

Re: [perl #22229] [no subject]

Thread Previous | Thread Next
From:
Slaven Rezic
Date:
May 17, 2003 18:19
Subject:
Re: [perl #22229] [no subject]
Message ID:
87k7cp2gtv.fsf@vran.herceg.de
Roman Hlynovskiy (via RT) <perlbug-followup@perl.org> writes:

> # New Ticket Created by  Roman Hlynovskiy 
> # Please include the string:  [perl #22229]
> # in the subject line of all future correspondence about this issue. 
> # <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=22229 >
> 
> 
> Hello , perlbug
> 
> i think i found some kind of bug. below you'll find short description
> and this is the sample, showing it...
> 
> ----------------------------------------------------------------------
> [root@lnx01][capturer]#> cat gluck.pl
> #!/usr/bin/perl
> 
> $a = 0;
> $b = 0;
> 
> print "increasing a to 1\n" if ($a++);
> print "increasing a to 2\n" if ($a++);
> 
> print "increasing b to 1\n" if ($b+=1);
> print "increasing b to 2\n" if ($b+=1);
> 
> print "increasing c to 1\n" if ($c++);
> print "increasing c to 2\n" if ($c++);
> 
> print "increasing d to 1\n" if ($d+=1);
> print "increasing d to 2\n" if ($d+=1);
> [root@lnx01][capturer]#> ./gluck.pl 
> increasing a to 2
> increasing b to 1
> increasing b to 2
> increasing c to 2
> increasing d to 1
> increasing d to 2
> ----------------------------------------------------------------------
> i.e. if trying to increase zero-valued (or undefined) scalar the
> result is always false if using '++' operator.
> below is perl -V from my system. i also tried it on 5.005_03 and it
> worked the same manner.

This works as expected, because $var++ is the post increment operator.
If you want pre increment, then use ++$var instead.

Regards,
	Slaven

-- 
Slaven Rezic - slaven@rezic.de

    tktimex - project time manager
    http://sourceforge.net/projects/ptktools/

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About