>         foreach my $i ( sort { $a <=> $b } (keys (%hash))) {
>                print "$i => $hash{$i}\n" if ( defined $hash{$i} );
>          }
> }
>

how about ....

      foreach my $i (     sort (   keys(%hash)   )     ) {
                print "$i => $hash{$i}\n" if ( defined $hash{$i} );
          }



----- Original Message -----
From: "Yacketta, Ronald" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, January 10, 2003 4:11 PM
Subject: sorting hash after deref


> Folks,
>
> Can some one kindly slap me silly and show me where I went south?
>
>
> sub dbMonthlySelect() {
>         my $query;
>         my $result;
>
>         $query = "select * from mbstats_se where
> STATDATE=TO_DATE('12/30/02','MM/DD/YY')";
>         $result = &doQuery($query,'dbMonthlySelect');
>
>         my %hash = %{$result->fetchrow_hashref};
>
>         foreach my $i ( sort { $a <=> $b } (keys (%hash))) {
>                print "$i => $hash{$i}\n" if ( defined $hash{$i} );
>          }
> }
>
> I want to sort the hash and print out only the defined key ⇔ value pairs
>
> -Ron
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Reply via email to