in reply to The biggest value in array 2 dimensin

You can also code this way (for N dimensions)

perl -le 'my $max="-inf";$array=[[100,20,[32,4]],51,[621,7],[82]]; sub fm { map { $max = ($max < $_) ? $_ : $max } map { ref() ? fm($_) : $_ } @{$_[0]} }; fm($array); print $max ' 621


Update : Initialised $max to "-inf" upon JavaFan's suggestion.

Replies are listed 'Best First'.
Re^2: The biggest value in array 2 dimensin
by JavaFan (Canon) on Oct 02, 2010 at 10:21 UTC
    Your program has a bug. Had you enabled warnings, you would have found out why. You never initialize $max, which means that in numeric context, $max is treated as if 0. Which means that if all your values are negative, at the end of the procedure, $max is never assigned a new value and still undefined.

    You ought to initialize max to negative infinity:

    my $max = "-inf";