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

[perl #133134] map{ /.../; { %+ } } @data wrongly flattens hashesinto arrays

Thread Next
From:
James E Keenan via RT
Date:
April 21, 2018 01:10
Subject:
[perl #133134] map{ /.../; { %+ } } @data wrongly flattens hashesinto arrays
Message ID:
rt-4.0.24-13872-1524273037-958.133134-15-0@perl.org
On Fri, 20 Apr 2018 20:25:49 GMT, jim.avera@gmail.com wrote:
> 
> This is a bug report for perl from jim.avera@gmail.com,
> generated with the help of perlbug 1.40 running under perl 5.26.1.
> 
> -----------------------------------------------------------------
> If used inside map{...}, the construct
> 
> { %+ }
> 
> results in a flat list of keys and values, not a ref to a hash.
> For example,
> 
> map{ /^(?<a>A*)(?<b>B*)$/ or die; { %+ } } ("AB", "AABBB", "AAAB");
> 
> returns
> 
> ('a', 'A', 'b', 'B', 'a', 'AA', 'b', 'BBB', 'a', 'AAA', 'b', 'B')
> 
> instead of
> 
> ( {'a' => 'A', 'b' => 'B' }, etc. )
> 
> A demo script follows.
> 
> #!/usr/bin/perl
> use strict; use warnings;
> use Data::Dumper;
> 
> my @list1;
> foreach ("AB", "AABBB", "AAAB") {
>   /^(?<a>A*)(?<b>B*)$/ or die;
>   push @list1, { %+ };
> }
> my @list2 = map{ /^(?<a>A*)(?<b>B*)$/ or die; { a=>$+{a}, b=> $+{b} }
> }
>             ("AB", "AABBB", "AAAB");
> my @list3 = map{ /^(?<a>A*)(?<b>B*)$/ or die; { %+ } }
>             ("AB", "AABBB", "AAAB");
> 
> print Data::Dumper->Dump([\@list1,\@list2,\@list3], [qw(list1 list2
> list3)]);
> 
> 

Using perlbrew, I checked out various production releases of perl, ran your program in each and recorded the results.  See attachment.

The program wouldn't compile in 5.8.9, but did in 5.10.1.  From 5.10.1 the result was stable up through 5.16.3.  As of 5.18.4 the results differ each release.  (I haven't looked closely enough to see whether or not this is just reshuffling of hash elements.)

So this does not appear to be a regression appearing for the first time in the 5.27 dev cycle.

Thank you very much.
-- 
James E Keenan (jkeenan@cpan.org)

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

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