sub select_your_school { my $namesref = shift; # create a list of sorted hash keys my @menuitems = sort keys %$namesref; print $q->header, $q->start_html(-title=> 'Select Your School'), "Please select your school from the following list:", $q->start_form, $q->popup_menu( {-name => 'school_id', -values => \@menuitems , }), ....

Or you could do it in one step:
sub select_your_school { my $namesref = shift; print $q->header, $q->start_html(-title=> 'Select Your School'), "Please select your school from the following list:", $q->start_form, $q->popup_menu( { -name => 'school_id', -values => [ sort keys %$namesref ], }), .....

Various sorting options:
# Sort by alpha sort keys %$namesref # Sort by alpha reverse order sort { $b cmp $a } keys %$namesref # Sort by numeric value sort { $a <=> $b } keys %$namesref # etc...

In reply to Re: Sorting my hashref by value for printing a popup_menu using CGI by Roger
in thread Sorting my hashref by value for printing a popup_menu using CGI by jerrygarciuh

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.