develooper Front page | perl.perl5.porters | Postings from February 2023

Re: PERL_RC_STACK branch: first cut

Thread Previous | Thread Next
From:
"Ruud H.G. van Tol" via perl5-porters
Date:
February 27, 2023 11:45
Subject:
Re: PERL_RC_STACK branch: first cut
Message ID:
03a5ebd7-e3e5-d950-63f4-cf4097a016e8@isolution.nl

On 2023-02-27 12:20, demerphq wrote:
> For those who want a simple example of the bug that this patch fixes 
> here is a simple example:
>
> With blead perl this program should print out "foo", but does not.
> $ perl -le'my @a=("foo"); sub t {@{$_[0]}=(); print $_[1];} 
> t(\@a,$a[0]);'
>
> With Dave's branch it behaves as expected:
> $ ./perl -le'my @a=("foo"); sub t {@{$_[0]}=(); print $_[1];} 
> t(\@a,$a[0]);'
> foo
>

To me that is a confusing example.

I don't see (yet) how/why it should print out "foo".
Details below.

-- Ruud


-- -- -- -- -- -- -- --

Why would you want/expect it to print "foo",
when you are using aliased parameters,
and are deliberately emptying the array?


If you really want it to print "foo", just code differently, to have 
copies where needed?

perl -Mv5.28 -wE'my @a=("foo"); sub t {@{$_[0]}=(); say $_[1];} t(\@a, 
"$a[0]");'
foo

perl -Mv5.28 -wE'my @a=("foo"); sub t ($p1, $p2) {@$p1=(); say $p2;} 
t(\@a, $a[0]);'
foo


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