From: "Connie Chan" <[EMAIL PROTECTED]>

> Thanks in advise =)
> 
> In case, my source is not an Excel spread sheet, but a Hash Of Array.
> So is that mean if I want to use this function, then I have to convert
> my HOA to Spreadsheet, then use the method below to sorting about ? Or
> anything I can do more direct ? Or anything can let me directly
> convert a HOA to CVS ? I would apperciate for any further hints.
> Thanks !!!

Are you sure it's a HashOfArrays and not an ArrayOfHashes?

#HAO

$data{$key} = ['Jenda', 'Krynicky', '[EMAIL PROTECTED]', ...]

# AOH
$data[$i] = {fname => 'Jenda', lname => 'Krynicky', email => 
'[EMAIL PROTECTED]', ...}

Keep in mind that hash is not ordered!


If you want to sort the AOH using a field you can do it like this:

        @sorted_data = sort {$a->{$key} cmp $b->{$key}} @data;
        #ascending
or
        @sorted_data = sort {$b->{$key} cmp $a->{$key}} @data;
        #descending

where $key is the name of the field you want to use.
If you want to sort using several fields you can do it like this:

        @sorted_data 
                = sort {$a->{$key1} cmp $b->{$key1} or $a->{$key2} cmp $b->{$key2}}
                        @data;

HTH, Jenda

=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
                                        --- me


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

Reply via email to