[EMAIL PROTECTED] wrote:
> All,
> 
> I have a two-dimension hash which I use to print out information I
> retrieved from a DB. I am using a unique identifier as the key to
> avoid duplicates. However, I need to sort the entire hash by date,
> which is a key on the second level of the hash. How can I sort this?
> Example: 
> 
> ### CODE
> 
> foreach my $key (keys %results) {
        NOttested, but something along the line:
  foreach my $key (sort { $results->{$a}{'DATA'} cmp $results->{$b}{'DATA'} } 
keys %results ) {
Now if the dates are not constant as you show then you might have to do map and 
paly with the data to get it sorted, but from data provided, this should be a 
start for you.

Wags ;)
>       $total_built++;
>       print <<EOM;
>               <tr>
>                       <td class="Regular" width="20%">
>                               $results{$key}{'SERIAL'}
>                       </td>
>                       <td class="Regular" width="20%">
>                               $results{$key}{'DATE'}
>                       </td>
>                       <td class="Regular" width="20%">
>                               $results{$key}{'TA'}
>                       </td>
>                       <td class="Regular" width="20%">
>                               $results{$key}{'MODEL'}
>                       </td>
>                       <td class="Regular" width="20%">
>                               $results{$key}{'WIP'}
>                       </td>
>               </tr>
> EOM
> }
> 
> ### OUTPUT
> 
> P0174751  2006-03-07 11:24:40.550  TA-F10-072343  RTLO-18918B  320518
> P0174948  2006-03-07 10:20:14.417  TA-D60-048793  FRO-16210C  322604
> 
> What I want is the records to appear on chronological order. I
> originally implemented this with a simple array and the actual SQL did
> the sorting for me but I needed to get rid of the duplicates and the
> only means I could find was by copying to a hash, using the unique ID
> as key to overwrite any duplicates on the resulting hash. But now I
> lost the original SQL sorting after the copy. Please advise.
> 
> Regards,
> 
> Javier Moreno
> -------------
> 
> Eaton | Truck Components
> Systems Engineer - Transmissions
> 
> "When you have eliminated all which is impossible, then whatever
> remains, however improbable, must be the truth" - Sherlock Holmes
> 
> _______________________________________________
> ActivePerl mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to