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

Re: sorting question

by Enlil (Parson)
on Oct 17, 2004 at 20:04 UTC ( #399963=note: print w/ replies, xml ) Need Help??


in reply to sorting question

This assumes you will have the same amount of x's as y's or you'll get a whole lot of uninitialized warnings (granted there are ways around that):

use strict; use warnings; my $xy = [ [5,4,2,3,1,12], [2,9,2,3,4,5] ]; my @xy; #push x's and corresponding y coor. in #a slight different AoA; for ( 0 .. $#{$xy->[0]} ){ push @xy, [ $xy->[0][$_], $xy->[1][$_] ]; } #sort it by y; @xy = sort { $a->[1] <=> $b->[1] } @xy; print "value of x with largest y = $xy[-1][0]\n"; print "largest y = $xy[-1][1]\n";


Comment on Re: sorting question
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2015-07-05 18:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls