develooper Front page | perl.perl5.porters | Postings from November 2018

[perl #133538] refaliasing does not work

From:
James E Keenan via RT
Date:
November 1, 2018 15:46
Subject:
[perl #133538] refaliasing does not work
Message ID:
rt-4.0.24-25224-1541087205-315.133538-15-0@perl.org
On Sat, 22 Sep 2018 09:56:45 GMT, kes-kes@yandex.ru wrote:
> Reply-To: kes-kes@yandex.ru
> Message-Id: <5.24.1_18064_1537609447@work>
> To: perlbug@perl.org
> Subject: refaliasing does not work
> From: kes-kes@yandex.ru
> Cc: kes-kes@yandex.ru
> 
> 
> This is a bug report for perl from kes-kes@yandex.ru,
> generated with the help of perlbug 1.40 running under perl 5.24.1.
> 
> 
> -----------------------------------------------------------------
> [Please describe your issue here]
> 
> https://perldoc.perl.org/perlref.html#Making-References
> 
> my @list = ( 1, 2, 3 );
> 
> # Test 1
> my %hash =  ();
> {
>         \( @hash{qw/ a b c /} ) =  \(@list);
> }
> print %hash;  # abc
> 
> 
> values are destroed from hash when we leave the block
> 
> It is same for this:
> 
> my %hash =  ();
> {
>     \( @hash{qw/ a b c /} ) =  (\$list[0], \$list[1], \$list[2]);
> }
> print %hash;  # abc
> 
> 
> But individual aliasing works fine:
> # Test 6
> %hash =  ();
> {
>     \$hash{a} =  \$list[0];
>     \$hash{b} =  \$list[1];
>     \$hash{c} =  \$list[2];
> }
> print "Test 6: @{[ %hash ]}\n"; # a 1 b 2 c 3
> 
> 
> See attached file for full test list

Do we have a similar problem for array slice assignment with refaliasing within a block?

See attachment 133538-refalaising-array-slice.pl.

#####
$> perl 133538-refalaising-array-slice.pl
ok 1 - simple array slice assignment
ok 2 - array slice assignment with refaliasing
ok 3 - simple array slice assignment within block
not ok 4 - array slice assignment with refaliasing within block
#   Failed test 'array slice assignment with refaliasing within block'
#   at 133538-refalaising-array-slice.pl line 25.
#     Structures begin differing at:
#          $got->[4] = undef
#     $expected->[4] = '1'
Got:
$VAR1 = [undef,undef,undef,undef,undef,undef,undef];
Expected:
$VAR1 = [undef,undef,undef,undef,1,2,3];
1..4
# Looks like you failed 1 test of 4.
#####

Thank you very much.

-- 
James E Keenan (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=133538



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