Perl Monk, Perl Meditation PerlMonks

### Comment on

 Need Help??
Here's my reformatting with a couple of minor changes:
```#!/usr/bin/perl
use strict;
use warnings;

use constant MAX     => 50;
use constant Height  => 25;
use constant Indent  => 7;
use constant Periods => 96;

my @Data;

my \$Element = 0;
while(\$Element < 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 > \$Data[\$Period] ? \$HighestValue :
+ \$Data[\$Period];
}

#
# Calculate Scale
#
#
my \$Scale = \$HighestValue > \$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 * \$Scal
+e) . (\$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 > \$Row)
{
substr(\$Rows[\$Row], \$Period + \$Indent, 1) = '|';
}
}
}

return(join( "\n", reverse( @Rows ), ' Time: ' . '|^^^' x ( \$Period
+s / 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

In reply to Re: ascii graph by NateTut
in thread ascii graph by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
 erix .oO( apparently but does not GotToBFast ) [Discipulus]: now i must come back to my house/hoven monks: dont do interesting discussion in my absence! [erix]: or apparently, now it does :) [GotToBTru]: heh erix prods ambrus to (re-)start cbstream... [GotToBTru]: I've got a program with an if ... or ... statement with 80 clauses [stevieb]: 80 clauses? dispatch table? [GotToBTru]: no, lookup [stevieb]: no, I mean have you considered using a dispatch table. an 80 condition if/else is huge :) [GotToBTru]: that is how this should have been done, no question

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (11)
As of 2017-06-22 12:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How many monitors do you use while coding?

Results (519 votes). Check out past polls.