in reply to Re: How do I order a hash for use as a %label list in cgi.pm?
in thread How do I order a hash for use as a %label list in cgi.pm?

Yes, thank you, I know, I read the pod too. ;)

The problem is that when you pass -labels=>\%labels, it creates the menu in random order.

The question is how to use this module to get an ORDERED list, not a random one. So that "Item A", "Item B", "Item C" are listed in alphabetical order versus random, which is what happens when you pass a hash of \%labels.

-- Filmo the Klown

  • Comment on Re: Answer: How do I order a hash for use as a %label list in cgi.pm?

Replies are listed 'Best First'.
Re: Re: Answer: How do I order a hash for use as a %label list in cgi.pm?
by chipmunk (Parson) on Mar 21, 2001 at 23:06 UTC
    The order of the hash of labels doesn't matter, because the array of values is ordered.
      Thanks, definity one of those "duh" things that seems so obvious after you hear the right answer.

      But, what if the values of the list are some unique randomly generated user id such as "9322042" and the Labels are supposed to be "Arnold", "Bob", "Clark", etc. How does one get the labels that appear in the menu to be alphabetical even thought the values are not similarly ordered.
      --
      Filmo the Klown

        Sort the keys by comparing the values: my @values = sort { $labels{$a} cmp $labels{$b} } keys %labels;