use strict; use warnings; use Test::More; use B::Deparse; my $animals; my $deparse = B::Deparse->new; $deparse->ambient_pragmas(strict => 'all', warnings => 'all'); # Function to check that each solution works! sub this_works (&) { $animals = { gnu => { humps => 0, }, dromedary => { humps => 1, }, camel => { humps => 2, }, }; my @results = $_[0]->(); my $code = $deparse->coderef2text($_[0]); if (is_deeply [sort @results], [qw/ 0 1 2 /] ) { diag "this works $code"; } else { diag "FAILED! $code"; } } this_works { map($_->{humps}, values %$animals) }; this_works { map { $_->{humps} } values %$animals }; this_works { map { $animals->{$_}{humps} } keys %$animals }; this_works { require JSON::Path; JSON::Path->new('$..humps')->values($animals); }; done_testing();