<?xml version="1.0" encoding="windows-1252"?>
<node id="763874" title="Re: ascii graph" created="2009-05-13 14:45:59" updated="2009-05-13 14:45:59">
<type id="11">
note</type>
<author id="337321">
NateTut</author>
<data>
<field name="doctext">
Here's my reformatting with a couple of minor changes:
&lt;c&gt;
#!/usr/bin/perl
use strict;
use warnings;

use constant MAX     =&gt; 50;
use constant Height  =&gt; 25;
use constant Indent  =&gt; 7;
use constant Periods =&gt; 96;

my @Data;

my $Element = 0;
while($Element &lt; Periods)
   {
   # $Data[$Element] = $Element;
   $Data[$Element] = int(rand(MAX));
   $Element++;
   }

print(ASCII_Graph(Height, Indent, Periods, @Data));

######################################################################­#
### give me an array of 96 integers that represent each of the
### 15-minute intervals in 24 hours.  I'll give you an ascii graph
### (of, e.g., concurrent users?)
sub ASCII_Graph
{
   my ($Height, $Indent, $Periods, @Data) = @_;

   my $HighestValue = 0;
   my @Rows = ();

   #
   # Find the Top Value
   #
   for my $Period (0 .. $Periods - 1)
      {
      $HighestValue = $HighestValue &gt; $Data[$Period] ? $HighestValue : $Data[$Period];
      }

   #
   # Calculate Scale
   #
   #
   my $Scale = $HighestValue &gt; $Height ? ( $HighestValue / $Height ) : 1;

   #
   # Do Each Row
   #
   for my $Row (0 .. $Height)
      {
      #
      # Label Every Other Row
      #
      if($Row % 2)
         {
         $Rows[$Row] = sprintf("%" . ($Indent - 1) ."d ", $Row * $Scale) . ($Row % 5 == 0 ? '_' : '.') x $Periods;
         }
      else
         {
         $Rows[$Row] = sprintf("%" . ($Indent - 1) ."s ", ' ') . ($Row % 5 == 0 ? '_' : '.') x $Periods;
         }

      for my $Period (0 .. $Periods - 1)
         {
         #
         # Determine
         if ($Data[$Period] / $Scale &gt; $Row)
            {
            substr($Rows[$Row], $Period + $Indent, 1) = '|';
            }
         }
      }

   return(join( "\n", reverse( @Rows ), ' Time: ' . '|^^^' x ( $Periods / 4 ), ' ' x $Indent . '12am    2am     4am     6am     8am    10am    12pm     2pm     4pm     6pm     8pm    10pm'));
}  # end sub graph
__END__
    49 ________________________________________________________________________________________________
       ...................................|.....................|.......|..............................
    45 ...........|......|............|...|...........|.........|.......|..............................
       ...........|......||...|.......|...|.......|...||..|.....||......|..............|...............
    41 ...........|......||...|..|....|...|....|..|...||..|.....||......|..............|...............
       ___________|______||___|__|____|___|____|__|___||__|_____||______|__|____|______|_______|_______
    37 ...........|....|.||...|..|....|...|....||.|...||..|.....||....|.|..|....|......|.......|.......
       ...........|....|.||...|..|.|..|...|....||.||..||..|....|||....|.|..|....|......|...|...|..|....
    33 ...........|....|.||...|..|||..|...|....||.||..||..||...|||....|||..|....|......|.|.|...|..|....
       ...........|....|.|||..|..|||..|..|||...||.||..||..||...|||....|||..|....||.....|.|.|...|..|....
    29 ___________|___||_|||__|__|||__|__|||___||_||__||__||___|||____|||__|____||_____|_|_|___|__|____
       ....|......|...||.|||.||..|||.||..||||..||.||..||..||...|||...||||..|....||.....|.|.|.|.||.|....
    25 ...||...||.|...||.|||.||..|||.||..||||..|||||..||..||...|||...||||..|....||.....|.|.|.|.||.|....
       ...||...||.|...||.||||||..|||.||..||||..|||||..||..||...|||...||||..|....||.....|||.|.||||.|.|..
    21 .|.||...||.|...||.||||||..|||.||..||||..|||||..||..||.|||||.|.||||.||....||.....|||.|.||||.|.|..
       _|_||_|_||_||__||_|||||||_|||_||__||||__|||||__||__||||||||_|_|||||||____||_____|||_|_||||_|_||_
    17 .|.||.|.|||||..||.|||||||.|||.||..||||..||||||.||..||||||||.|.|||||||....||..|..|||.|.||||||.||.
       .|.||.|.|||||..||.|||||||.|||.||..|||||.||||||.||..||||||||||.|||||||.|.|||..|..|||.||||||||.||.
    13 .|.||.|.|||||..||.|||||||.|||.||..|||||.||||||.||..||||||||||||||||||.|.|||..|.|||||||||||||.|||
       .||||||.|||||..||.|||||||.|||.||..|||||.||||||.||..||||||||||||||||||.|||||..|.|||||||||||||.|||
     9 _||||||_|||||__||_|||||||_|||_||__||||||||||||_||__||||||||||||||||||||||||_||||||||||||||||||||
       .||||||.|||||||||.|||||||.|||.|||.||||||||||||.||..||||||||||||||||||||||||.||||||||||||||||||||
     5 .||||||.|||||||||.|||||||.|||.|||.||||||||||||.||.||||||||||||||||||||||||||||||||||||||||||||||
       .||||||||||||||||||||||||.|||||||.|||||||||||||||.||||||||||||||||||||||||||||||||||||||||||||||
     1 .||||||||||||||||||||||||||||||||.||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
       |||||||||||||||||||||||||||||||||_||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 Time: |^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^
       12am    2am     4am     6am     8am    10am    12pm     2pm     4pm     6pm     8pm    10pm

&lt;/c&gt;

&lt;!-- Template:
&lt;code&gt;&lt;/code&gt;&lt;br&gt;&lt;b&gt;&lt;/b&gt;
&lt;readmore title=""&gt;...&lt;/readmore&gt;
&lt;spoiler&gt;
[nodetitle]
[id://nodeid] 2
[pad://monk name]
[pad://]
[search terms]
[mod://XML::Parser]
[module://XML::Parser]
[cpan://XML::Parser]
[kobes://XML::Parser]
[perldoc://search terms]
[doc://document name]
[doc://function name]
[google://search terms]
[lucky://search terms]
[google://parse HTML site:stonehenge.com]
[isbn://1565922840]
[jargon://search terms]
[http://perl.com/]
[https://]
[ftp://]
&lt;A HREF="..."&gt;&lt;/A&gt;
[http://perlmonks.org|The Perl Monastery]


&lt;p&gt;&lt;em&gt;&lt;/em&gt;&lt;/p&gt;
&amp;#91; &amp;#93;
&amp;	&amp;amp;
&lt;	&amp;lt;
&gt;	&amp;gt;
[	&amp;#91;
]	&amp;#93;
--&gt;</field>
<field name="root_node">
336907</field>
<field name="parent_node">
336907</field>
</data>
</node>
