develooper Front page | perl.perl5.porters | Postings from March 2001

Re: unexpected result of stringification.

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
March 20, 2001 06:29
Subject:
Re: unexpected result of stringification.
Message ID:
200103201412.OAA13820@gizmo.fdgroup.co.uk
<abigail@foad.org> wrote:
>The lead role is &&. The example

I think you'll find this behaviour is common to many most (all?) operators
- ie using a varibale rather than its value. Eg the following all print
out 6 rather than 5.

$a = (($x = 2) && $x) + (($x = 3) && $x);
print $a;

$a = (($x = 2),$x) + (($x = 3), $x);
print $a;

$x = 1; $a = ++$x + ++$x;
print $a;

$a = ($x ? $x : 0) + (($x = 3), $x);
print $a;


In all these cases, when pp_add() is called, there are 2 pointers on
the stack to the SV associated with $x, rather than 2 pointers to
2 copies of $x.


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