While this is slightly off from your question. One thing about using CGI.pm that stinks is when you provide a hash so you can have different values and labels (as you are trying to do) it doesn't sort them. If this is why you are avoiding using CGI.pm you can use the snippet below that I use. It's a simple tie that you can use to make it sort by value.
package SortHash; #Kludge to get options sorted. use Tie::Hash; use vars qw(@ISA); @ISA = qw( Tie::StdHash ); sub FIRSTKEY { my $self = shift; @{ $self->{_SORTHASH_KEYS} } = sort {$self->{$a} cmp $self->{$b} } + grep { $_ ne '_SORTHASH_KEYS' } keys %{$self}; return shift @{ $self->{_SORTHASH_KEYS} }; } sub NEXTKEY { my $self = shift; return shift @{ $self->{_SORTHASH_KEYS} }; } package main; use CGI qw(:standard); my %list; tie %list, 'SortHash' ; # tied hash with sorted keys by value... print start_form; print popup_menu(-name=>'option' , labels=> \%list, -values=> [ keys % +list ] ); print end_form;


-Lee

"To be civilized is to deny one's nature."

In reply to Re: Sorting by the hash value by shotgunefx
in thread Sorting by the hash value by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.