Date: 26 Jun 2001 11:47:12 -0500 From: Ren Maddox Subject: Re: how to sort array of similar hashes by one of the hash keys? Message-Id: You've already gotten the solution to your sort question, but I wanted to make one comment about your initialization code. On Tue, 26 Jun 2001, irfan@abstractedge.com wrote: > I've split data from a flatfile into hashes in an array, @game, all > of which have keys 'name', 'score' and 'date'. > > @game = (); > for ($i=0; $i<=$#scores; $i++){ > ($game[$i]{'name'},$game[$i]{'score'},$game[$i]{'date'}) = split(/,/, $data[$i]); > } This works fine, but it isn't very Perl-ish (not that there's anything wrong with that). A more Perl idiomatic way to do this might be: foreach (@data) { # or @scores ?? my %hash; @hash{qw/name score date/} = split /,/; push @game, \%hash; } or, if you want to be perverse.... @{$game[@game]}{qw/name score date/} = split /,/ for @scores; -- Ren Maddox ren@tivoli.com