Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

by tachyon (Chancellor)
on Apr 04, 2002 at 11:32 UTC ( [id://156625]=note: print w/replies, xml ) Need Help??


in reply to 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...

This is of course the gist but if you want it to compile :o) and look right (ie height of bars), perhaps you might:

my $results = { 'Category A' => 140, 'Category B' => 210 }; # Start your HTML here..... Then.... print qq(<table border="0">\n); foreach my $key (keys(%$results)) { print <<" HTML"; <br> <tr> <td> $key </td> <td> <img src="http://perlmonks.org/images/bluebox.gif" height=15 wid +th="$results->{$key}"> </td> <td> $results->{$key} width units </td> </tr> HTML } print "</table>\n";

cheers

tachyon

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

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

Replies are listed 'Best First'.
Re: Re: Re: How'd they do that...proportional horz. bars in poll results...
by S_Shrum (Pilgrim) on Apr 04, 2002 at 22:09 UTC

    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

      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.

      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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-19 09:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found