Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: How do I sort a multidimensional arrays?

by reptile (Monk)
on May 28, 2000 at 23:59 UTC ( [id://15220]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://15220]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-29 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found