in reply to How do I sort a multidimensional arrays?

@array = ([8,9,10], [4,5,6], [7,8,9]); @sorted = sort { $a->[1] <=> $b->[1] } @array

Updated and fixed thanks merlyn.

Replies are listed 'Best First'.
RE: Answer: How do I sort a multidimensional arrays?
by merlyn (Sage) on May 29, 2000 at 19:05 UTC
    In our last episode, we saw:
    @array = [8,9,10], [4,5,6], [7,8,9]; @sorted = sort { $a->[1] <=> $b->[1] } @array
    in which our nearly knowledgable hero is probably now thumping his head on his desk, realizing that he should have written:
    @array = ([8,9,10], [4,5,6], [7,8,9]); @sorted = sort { $a->[1] <=> $b->[1] } @array
    Because the precedence rules say so, otherwise the second and third element are just tossed off to never-never land.

    -- Randal L. Schwartz, Perl hacker

      You're right about that. I wasn't paying attention and just copied the line from the question. DOH.

      72656B636148206C72655020726568746F6E41207473754A