http://www.perlmonks.org?node_id=997972


in reply to problem with array of hashes

The expression +(sort { $a <=> $b } keys %{ $VAR1->[0] })[0] returns 41.

Replies are listed 'Best First'.
Re^2: problem with array of hashes
by tobyink (Canon) on Oct 09, 2012 at 10:47 UTC

    So does:

    my ($value) = map { join('array of hashes', 41) } $VAR;

    Update: added parentheses. Thanks McA.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

      Oh, oh, oh

      Guys, look at this:

      use strict; use warnings; use Test::More tests => 2; my $the_ultimate_answer = 42; my $VAR1 = [ { '201' => 'i', '101' => 'f', '41' => 't', } ]; is(+(sort { $a <=> $b } keys %{ $VAR1->[0] })[0], $the_ultimate_answer +, 'Testing for ultimate answer'); my $value = map { join('array of hashes', 41) } $VAR1; is($value, $the_ultimate_answer, 'Testing for ultimate answer');

      The second proposal is more wrong than I expected. ;-)

Re^2: problem with array of hashes
by grizzley (Chaplain) on Oct 09, 2012 at 11:13 UTC
    ...and print +(sort {$VAR1{$a} <=> $VAR1{$b}} keys %{$VAR1->[0]})[-1]