jiwei800715 has asked for the wisdom of the Perl Monks concerning the following question:

I want to make a index text file for many data files , I use AoH to build index,
my @AoH=( {secID=>'SZ0001', date=>20090201, dataentry=>1, # dataentry is start address in data file '200902 +01.bin' filename=>'20090201.bin'} {secID=>'SZ0002', date=>'20090201' dataentry=>2, filename=>'20090201.bin'} {secID=>'SZ0001', date=>'20090202' dataentry=>1, filename=>'20090202.bin'} {secID=>'SZ0002', date=>'20090202' dataentry=>2, filename=>'20090202.bin'} )
this kind of data is really like table in database,and I want to sort these rows(hash) first by "date" and then by "dataentry", also can easily search result given by "SecID" and "Date".

Is there any better way to go ?

thx

Replies are listed 'Best First'.
Re: AoH sort & search
by grizzley (Chaplain) on Feb 25, 2009 at 12:25 UTC
    Try

    sort {$a->{'date'} <=> $b->{'date'} || $a->{'dataentry'} <=> $b->{'dataentry'}} @AoH;

    Check first comment in Sorting AoH by two keys for good explanation how it works.

Re: AoH sort & search
by Anonymous Monk on Feb 25, 2009 at 12:01 UTC
Re: AoH sort & search
by Bloodnok (Vicar) on Feb 25, 2009 at 12:38 UTC
    You might've put your code/example in code (<c></c>) tags - it would make it far more readable (see How do I post a question effectively?).

    A user level that continues to overstate my experience :-))