Ah! ... had is ass-backwards, I though it didn't look right. Thank you for your help...much appreciated :)


Paul Archer wrote:
7:22pm, Mike Blezien wrote:

Hello,

I've gone through serveral posting regarding sorting hashes, but can't seem to get it to sort correctly. I need it to sort on the key value and not the key
it reads from a file like this:


1::sometext_here
2::sometext_here2
3::sometext_here3

And reads the data like this:
##############################################
my $lang = {};
    open(LANG,"<$langaugefile") or die ("Can't open $langaugefile $!");
    while (<LANG>)    {
        chomp $_;
        next  if $_ =~ /^\s*#/;
        next  unless $_ =~ /\S/;
           my($name,$value) = split /::/, $_;
        $lang->{$name}   = $value;
    }
    close(LANG);
return $lang;
###############################################
# then takes the return $lang hash for sorting

foreach $key (sort { $a->{$key} cmp $b->{$key} } keys(%{$lang}))


Close, but no cee-gar. The variables $a and $b are the temporary variables that represent what you are sorting by. So the 'keys(%{$lang})' provides what you are sorting (the keys)--so $a and $b represent keys. Therefore, your expression should be (sort { $lang->{$a} cmp $lang->{$b} }...

Paul



  {
    # do stuff
  }




-- Mike(mickalo)Blezien =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Thunder Rain Internet Publishing Providing Internet Solutions that work! =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to