in reply to Max dimensions of multi-dimensional array

just for my amusement..
perl -e "$array[345][10]=1;$array[2][65535]=1; print qq($#array x ),ma +p{scalar @$_ -1}(sort{scalar @$b<=>scalar @$a}@array)[0]" 345 x 65535

Dunno why i needed to swap $a and $b ..

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Max dimensions of multi-dimensional array -- oneliner
by GrandFather (Saint) on Jul 13, 2016 at 20:42 UTC

    Because you use the first element from your sorted list instead of the last.

    scalar isn't needed in the sort comparison because <=> puts the two array references into scalar context any way. For your code to be strictly correct (run without error under strictures) you need to deal with undefined array elements too. The cleaned up and strictly correct code looks like:

    use warnings; use strict; my @array; $array[345][10] = 1; $array[2][65535] = 1; print qq($#array x ), map {scalar @$_ - 1} (sort {@$a <=> @$b} map {$_ // []} @array)[-1 +];

    Prints:

    345 x 65535
    Premature optimization is the root of all job security
      Oh the hot summer air has obnubilated my mind.. thanks GrandFather for your fresh breeze!

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.