in reply to Document with Graphics

Not the question you asked, but... I find that ascii art can work wonders at times:
my %data = ( first => 12, second => 45, third => 27 ); foreach my $bit ( keys %data ) { print "$bit:\t", '-' x $data{$bit}, " $data{$bit}\n"; }
Produces:
first: ------------ 12 second: --------------------------------------------- 45 third: --------------------------- 27
It may not be perty but it is fast, flexible and portable.

--tidiness is the memory loss of environmental mnemonics

Replies are listed 'Best First'.
Re: Re: Document with Graphics
by Fletch (Bishop) on Mar 25, 2004 at 15:09 UTC

    Of course if you use s?printf() to format things so that the initial character of your graph lines up correctly it's a bit "pertyer".

    ... printf "%8s:\t%s %2d\n", $bit, "-" x $data{$bit}, $data{$bit}; ...

    Update: And of course you can get even fancier by making your graph lines a fixed width (say 50 characters) and mapping that into marks and spaces so that the actual values are lined up nicely as well.

    ... my $marks = "-" x int( ( $data{ $bit } / MAXDATA ) * 50.0 ); my $blanks = " " x ( 50 - $data ); printf "%8s:\t%s%s %2d\n", $bit, $marks, $blanks, $data{ $bit };
      But if we are getting fussy then we can't assume that the keys in the hash are less than eight letters long (or that tabs are 8 chars). With this assumption we'll lose alignment for large keys:
      small: ----- 5 really big key: -------- 8
      I see that you reduce the keys to 8 chars, but this may not work for keys such as "TotalSales2003", "TotalSales2004" etc. This is why I hate 'pertyness', there is always something to break it...

      --tidiness is the memory loss of environmental mnemonics