Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re: Re: More Sorted Business with Hashes

by Hrunting (Pilgrim)
on Dec 23, 2001 at 23:19 UTC ( [id://134084]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: More Sorted Business with Hashes
in thread More Sorted Business with Hashes

Actually, to amend this, now that I've read it a few days later, you typically use a hash mapped from 'value' to 'text', so if your structure is like the one above, you may have something like:
print $q->scrolling_list( '-name' => 'acct_num', '-values' => [ sort { $clients{$a} cmp $clients{$b} } keys %clients + ], '-labels' => \%clients, '-default' => $default_value );
Or, if for some wacky reason, your values really are the values for your menu and the keys are the text labels:
print $q->scrolling_list( '-name' => 'acct_nu', '-values' => [ sort values %clients ], '-labels' => { reverse %clients }, '-default' => $default_value );
Typically, when using CGI, the first way is the way most commonly used. Most people don't keep around sorted copies of hashes. It defeats the purpose of a hash. Hashes inherently are unsorted because the algorithm they use to make their lookups fast stores them (internally) in an optimal configuration (which is almost never sorted).

My fault for not reading the original scrolling_list() call correctly.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://134084]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-19 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found