I created a buggy function but my tests miraculously passed none the less.
I narrowed it down to this demo where sort is magically expanding stringified hashrefs like "HASH(0x253f0c8)" ...
(see <--- WTF? in output)
Could someone please explain the difference between sort AoH and sort {$a cmp $b } AoH here
OUTPUT:use v5.12; use warnings; use Data::Dump; my $AoH; debug_loop_join();exit; sub loop_join { my %H; $H{$_} = () for @$AoH; return keys %H; } sub debug_loop_join { $AoH = create_data (.2, 10); ddx [ loop_join ($AoH) ]; ddx [ sort loop_join ($AoH) ]; ddx [ sort {$a cmp $b } loop_join ($AoH) ]; } sub create_data { my ($density, $records) = @_; my @AoH; push @AoH, {map { rand 100 <= $density ? ( $_ => $_ ) : () } "A" . +. "ZZ"} for 1 .. $records; return \@AoH; }
# sort_hash_bug.pl:18: [ # "HASH(0x253f0c8)", # "HASH(0x25350c8)", # "HASH(0x268aa20)", # "HASH(0xeea828)", # "HASH(0x2535548)", # "HASH(0x2535128)", # "HASH(0x268aab0)", # "HASH(0x2535260)", # "HASH(0x268a840)", # "HASH(0x268a918)", # ] # sort_hash_bug.pl:19: [ # <--- +WTF? # [ # {}, # { AZ => "AZ", EM => "EM", RY => "RY" }, # {}, # { GT => "GT", JR => "JR", RZ => "RZ" }, # { HY => "HY" }, # { HT => "HT" }, # { VH => "VH", WU => "WU" }, # { GR => "GR", HH => "HH", HM => "HM", JC => "JC", WJ => "WJ" }, # {}, # { BK => "BK", UH => "UH", XX => "XX", ZN => "ZN" }, # ], # ] # sort_hash_bug.pl:20: [ # "HASH(0x25350c8)", # "HASH(0x2535128)", # "HASH(0x2535260)", # "HASH(0x2535548)", # "HASH(0x253f0c8)", # "HASH(0x268a840)", # "HASH(0x268a918)", # "HASH(0x268aa20)", # "HASH(0x268aab0)", # "HASH(0xeea828)", # ]
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
In reply to sort AoH buggy? by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |