in reply to Re: Re: How'd they do that...proportional horz. bars in poll results...
in thread How'd they do that...proportional horz. bars in poll results...

Perfect...I know how to sort on keys but how can I sort them according to the values (hi-lo)?

TIA

======================
Sean Shrum
http://www.shrum.net

  • Comment on Re: Re: Re: How'd they do that...proportional horz. bars in poll results...

Replies are listed 'Best First'.
Re: Re: Re: Re: How'd they do that...proportional horz. bars in poll results...
by thelenm (Vicar) on Apr 04, 2002 at 22:19 UTC
    You can sort by value by changing
    foreach my $key (keys(%$results)) {
    in the above code to:
    foreach my $key (sort {$results->{$b} <=> $results{$a}} keys %$results +) {
    If you have a ton of results, this may be inefficient, and may want to use a Schwartzian transform instead. But it sounds like maybe you don't have to worry about that.
Re: Re: Re: Re: How'd they do that...proportional horz. bars in poll results...
by tachyon (Chancellor) on Apr 05, 2002 at 00:36 UTC

    Typos, typos.... foreach my $key ( sort {$results->{$b} <=> $results->{$a}} keys %$results ) {

    Note that we access our hash $results->{'some_key'} as $results is a reference to the hash. So too the %$results notation to dereference $results and give us the hash. If you just have a plain hash %results your code will look like:

    foreach my $key ( sort {$results{$b} <=> $results{$a}} keys %results ) + {

    You will need to change the other -> derefereces too if that is the case.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print