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

[perl #134193] Accessing @{^CAPTURE} before %{^CAPTURE} empties thelatter

Thread Previous | Thread Next
From:
Tony Cook via RT
Date:
June 13, 2019 00:22
Subject:
[perl #134193] Accessing @{^CAPTURE} before %{^CAPTURE} empties thelatter
Message ID:
rt-4.0.24-7672-1560385353-1247.134193-15-0@perl.org
On Wed, 12 Jun 2019 13:11:15 -0700, haukex@zero-g.net wrote:
> Hi all,
> 
> As reported by vr on PerlMonks 
> (https://www.perlmonks.org/?node_id=11101258), accessing @{^CAPTURE} 
> before %{^CAPTURE} causes the latter to become an empty, untied hash.
> 
> 
> $ perl -MData::Dumper -e '"a"=~/(?<X>a)/; print Dumper \%{^CAPTURE}, 
> \@{^CAPTURE}, tied(%{^CAPTURE})'
> $VAR1 = {
>            'X' => 'a'
>          };
> $VAR2 = [
>            'a'
>          ];
> $VAR3 = bless( do{\(my $o = 256)}, 'Tie::Hash::NamedCapture' );
> 
> 
> $ perl -MData::Dumper -e '"a"=~/(?<X>a)/; print Dumper \@{^CAPTURE}, 
> \%{^CAPTURE}, tied(%{^CAPTURE})'
> $VAR1 = [
>            'a'
>          ];
> $VAR2 = {};
> $VAR3 = undef;
> 
> 
> $ perl -v
> This is perl 5, version 28, subversion 1 (v5.28.1) built for x86_64-linux
> ...
> 
> 
> The output I would expect from the second example is:
> $VAR1 = [
>            'a'
>          ];
> $VAR2 = {
>            'X' => 'a'
>          };
> $VAR3 = bless( do{\(my $o = 256)}, 'Tie::Hash::NamedCapture' );

The magic setup code assumes it will be called separately for the array and hash (which is incorrect.)

The attached fixes it (applies on top of the 131867 fix).

I'll apply both in a few days unless someone sees a problem.

Tony

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

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