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

Re: Differences between state variables and smart matches in 5.10 and 6

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
March 26, 2007 13:13
Subject:
Re: Differences between state variables and smart matches in 5.10 and 6
Message ID:
20070326201346.GY5748@plum.flirble.org
On Mon, Mar 26, 2007 at 05:36:08PM +0200, Abigail wrote:

> It looks like the return value is the right hand side only if there's no
> assignment done - the first time it returns an lvalue:
> 
>   $ curperl -E 'sub f {(state $x = 42)++; say $x} f; f;'
>   43
>   Modification of a read-only value attempted at -e line 1.

So this would be a bug?

$ ./perl -Ilib -wlE 'sub foo :lvalue {state $a = 3}; print foo()++ for 1..3'
3
Can't return a readonly value from lvalue subroutine at -e line 1.


Nicholas Clark

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