# New Ticket Created by Sir Robert Burbridge # Please include the string: [perl #114966] # in the subject line of all future correspondence about this issue. # <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=114966 >
(distilled from log) 11:06 < sirrobert> r: my @arr; @arr.push(%(a => 1, b => 2)); say @arr.perl; 11:06 <+p6eval> rakudo 097361: OUTPUT«Array.new("a" => 1, "b" => 2)» 11:06 < sirrobert> I expected that to give me an array with one element that was a hash 11:06 < sirrobert> what did I do wrong? 11:07 < sirrobert> or maybe: how should I think about that? 11:07 < masak> push expects a list of things. if it finds a hash, it listifies the hash. 11:07 < sirrobert> ok, how do I get it not to listify things? 11:08 < sirrobert> if I want an array of hashes 11:08 < masak> r: my @a; @a.push({ a => 1, b => 2}); say @a.perl 11:08 <+p6eval> rakudo 097361: OUTPUT«Array.new({"a" => 1, "b" => 2})» 11:08 < sirrobert> ok 11:08 < sirrobert> so what I really have is: 11:09 < sirrobert> r: my @a; @a.push(%((1,2,3) Z=> (<a b c>))); say @a.perl; 11:09 <+p6eval> rakudo 097361: OUTPUT«Array.new("1" => "a", "2" => "b", "3" => "c")» 11:09 < sirrobert> is the "right" solution here to create the hash separately? but it still gets expanded... 11:09 < sirrobert> I think 11:09 < masak> yeah. 11:09 < masak> r: my @a; my %h = (1,2,3) Z=> (<a b c>); @a.push(%h); say @a.perl 11:09 <+p6eval> rakudo 097361: OUTPUT«Array.new("1" => "a", "2" => "b", "3" => "c")» 11:09 < masak> indeed. 11:09 < masak> r: my @a; my %h = (1,2,3) Z=> (<a b c>); @a.push({%h}); say @a.perl 11:10 <+p6eval> rakudo 097361: OUTPUT«Array.new({"1" => "a", "2" => "b", "3" => "c"})» 11:10 < sirrobert> ohh.. weird 11:10 < sirrobert> ok, I can live with that =) 11:11 < pmichaud> r: my @a; @a.push({ (1,2,3) Z <a b c> }); say @a.perl 11:11 <+p6eval> rakudo 097361: OUTPUT«Array.new(Block.new())» 11:11 < moritz> sirrobert: what's weird about it? 11:11 < sirrobert> the {%} seems redundant 11:11 < moritz> well, the {} makes an hash-in-an-item 11:11 < sirrobert> moritz: a workaround for the listification magic of push 11:11 < moritz> you can also say %h.item 11:12 < sirrobert> ok, that's a good paradigm for me to adopt for it 11:12 < sirrobert> I didn't previously have a concept of 'item' 11:13 < sirrobert> huh... push({%...}) interprets it as a hash but push: {%...} interprets it as a block 11:14 < moritz> that's weird 11:14 < sirrobert> verifying now ... 11:14 < moritz> r: my @h; @h.push: {%*ENV}; say @h[0].WHAT 11:14 <+p6eval> rakudo 097361: OUTPUT«Block()» 11:15 < moritz> r: my @h; @h.push({%*ENV}); say @h[0].WHAT 11:15 <+p6eval> rakudo 097361: OUTPUT«Block()» 11:15 < moritz> sirrobert: seems to be a block either way :( 11:15 < moritz> r: my %a; my @h; @h.push({%a}); say @h[0].WHAT 11:15 <+p6eval> rakudo 097361: OUTPUT«Hash()» 11:15 < moritz> r: my %a; my @h; @h.push: {%a}; say @h[0].WHAT 11:15 <+p6eval> rakudo 097361: OUTPUT«Hash()» 11:15 < moritz> erm, what? 11:15 < sirrobert> moritz: erm, indeed =) 11:16 < moritz> %*ENV makes it a block, %a a hash? 11:16 * moritz smeells a rakudobug 11:18 < sirrobert> r: my $h = {%(<a b>) Z=> (1,2)}; say $h.WHAT; 11:18 <+p6eval> rakudo 097361: OUTPUT«Block()» 11:19 < masak> moritz: that feels buggish, yes. 11:19 < masak> moritz: care to report it? 11:19 < sirrobert> sure 11:19 < sirrobert> if I copy/paste this discussion is that enough? I don't quite know how to describe it. 11:19 < moritz> yes, it's enough 11:19 < sirrobert> ok, one sec