in reply to Re: Re: how do I sort on two fields in a hash table?
in thread how do I sort on two fields in a hash table?
prints the correct results:#!/usr/bin/perl -w use strict; my @a; push @a,{x=>1,y=>1}; push @a,{x=>2,y=>1}; push @a,{x=>1,y=>2}; push @a,{x=>2,y=>3}; push @a,{x=>2,y=>2}; foreach(sort {$a->{x} <=> $b->{x} or $a->{y} <=> $b->{y}} @a){ print " $_->{x} $_->{y}\n"; }
$ ./sort.pl 1 1 1 2 2 1 2 2 2 3
|
|---|