GIDustin
Emperor
I need to sort an Array by one thing, then another.
If you need further details, I can give them to you, but it is kindof hard to explain.
I want to sort all my units, by their type (land, sea, air), but I dont want them in alphabeticall order (air, land, sea), so I made a hash:
$Hash{'Air'}=3;
$Hash{'Land'}=1;
$Hash{'Sea'}=2;
Units are put in another hash, like so:
$Units{'APC'}{'Type'}=Land;
$Units{'Tank'}{'Type'}=Land;
......
$Units{'Caraval'}{'Type'}=Sea;
to sort by type, you would do:
@AllUnits = keys %Units;
@AllUnits = sort {$Hash{$Units{$a}{'Type'}} <=> $Hash{$Units{$b}{'Type'}}} @AllUnits;
That sorts them by type, but they are not in alphabetical order within those types.
Hopefully I explained that correctly,
GIDustin
If you need further details, I can give them to you, but it is kindof hard to explain.
I want to sort all my units, by their type (land, sea, air), but I dont want them in alphabeticall order (air, land, sea), so I made a hash:
$Hash{'Air'}=3;
$Hash{'Land'}=1;
$Hash{'Sea'}=2;
Units are put in another hash, like so:
$Units{'APC'}{'Type'}=Land;
$Units{'Tank'}{'Type'}=Land;
......
$Units{'Caraval'}{'Type'}=Sea;
to sort by type, you would do:
@AllUnits = keys %Units;
@AllUnits = sort {$Hash{$Units{$a}{'Type'}} <=> $Hash{$Units{$b}{'Type'}}} @AllUnits;
That sorts them by type, but they are not in alphabetical order within those types.
Hopefully I explained that correctly,
GIDustin