develooper Front page | perl.perl5.porters | Postings from April 2019

negative array elements and local

Thread Next
From:
Tony Cook
Date:
April 23, 2019 05:10
Subject:
negative array elements and local
Message ID:
20190423051000.5lg5767daqtrp3fa@mars.tony.develop-help.com
While looking at #134028 I noticed that none of pp_aelem, pp_aslice
nor pp_multidref adjust the saved array index if they're negative when
localizing, ie. the negative array index isn't adjusted to a positive
index before being stored in the save stack.

Some simple examples of the results:

tony@mars:.../git/perl$ ./perl -Ilib -MData::Dumper -e '@x = (1); { local $x[-1] = 2; push @x, 3; } print Dumper(\@x)'
$VAR1 = [
          2,
          1
        ];
tony@mars:.../git/perl$ ./perl -Ilib -MData::Dumper -e '@x = (1,2); { local $x[-2] = 3; pop @x; } print Dumper\@x'
$VAR1 = [
          3
        ];

This was unexpected to me.

Should these ops adjust the index?

Tony

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