in reply to How to sort by the key value of an Array of Hash structure?
yields#!/usr/bin/perl -w use strict; my @array = ( { name => "proteobacteriai", size => 30 }, { phylum => "alphabacteria", size => 50 }, { name => "cytophaga", size => 10 }, ); for (@array) { print "Size (out of order) = ",$_->{size}, "\n"; } my @newarray = sort { $a->{size} <=> $b->{size} } @array; for (@newarray) { print "Size = ",$_->{size}, "\n"; }
C:\Code>perl sort_aoh.pl Size (out of order) = 30 Size (out of order) = 50 Size (out of order) = 10 size = 10 size = 30 size = 50
|
|---|