Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Sorting array with multiple values per keys

by snoopy (Deacon)
on Aug 12, 2008 at 23:56 UTC ( #703994=note: print w/replies, xml ) Need Help??


in reply to Sorting array with multiple values per keys

I know basic sorting but this goes too deep for me. In addition, is it bad to use the array to put strings with two 'artifical' elements. Is there another way to do it more efficient like:
$array->[0]->x=1;
$array->[0]->y=5;
...
Seems as if you want an array of named values (x, y, ...etc).

You may want to consider array of hashes (AoH).

#!/usr/bin/perl use warnings; use strict; use YAML; my @Array; $Array[0]{x} = 1, $Array[0]{y} = 5; # # Or more concisely... # $Array[3] = {x => 3, y => 9}; $Array[2] = {x => 3, y => 4}; $Array[1] = {x => 6, y => 2}; $Array[4] = {x => 8, y => 1}; my @Sorted = sort {$a->{x} <=> $b->{x} || $b->{y} <=> $a->{y}} @Array; print YAML::Dump(@Sorted);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://703994]
help
Chatterbox?
[Lady_Aleena]: SOB! Now I'm really trying to get qx(mp3info -p "%S" $file) but the spaces in the filenames are kicking my butt.

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2017-04-23 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (433 votes). Check out past polls.