0: #!/usr/bin/perl
1: use strict;
2: use warnings;
3:
4: print graph( @{[1..96]} );
5:
6: #######################################################################
7: ### give me an array of 96 integers that represent each of the
8: ### 15-minute intervals in 24 hours. I'll give you an ascii graph
9: ### (of, e.g., concurrent users?)
10: sub graph {
11: my( $i, $magic, $m, $p, $top, @g ) = ( 0, 20, 7, 96, 0, () );
12: for (0..$p-1) { $top = $top > $_[$_] ? $top : $_[$_] }
13: my $s = $top > $magic ? ( $top / $magic ) : 1; ### calculate scale
14: for (0..$magic) {
15: $g[$_] = sprintf("%".($m-1)."d ",$_*$s) . ($_%5==0?'_':'.') x $p;
16: for $i (0..$p-1) { substr($g[$_],$i+$m,1) = '|' if $_[$i]/$s>$_ } }
17: join( "\n", reverse( @g ), ' Time: ' . '|^^^' x ( $p / 4 ),
18: ' ' x $m . "12am 1am 2am 3am 4am 5am 6am 7am 8am 9a 10a 11a " .
19: "12pm 1pm 2pm 3pm 4pm 5pm 6pm 7pm 8pm 9p 10p 11pm" );
20: } # end sub graph
21:
22: __END__
23: 96 ________________________________________________________________________________________________
24: 91 ...........................................................................................|||||
25: 86 ......................................................................................||||||||||
26: 81 .................................................................................|||||||||||||||
27: 76 ............................................................................||||||||||||||||||||
28: 72 ________________________________________________________________________||||||||||||||||||||||||
29: 67 ...................................................................|||||||||||||||||||||||||||||
30: 62 ..............................................................||||||||||||||||||||||||||||||||||
31: 57 .........................................................|||||||||||||||||||||||||||||||||||||||
32: 52 ....................................................||||||||||||||||||||||||||||||||||||||||||||
33: 48 ________________________________________________||||||||||||||||||||||||||||||||||||||||||||||||
34: 43 ...........................................|||||||||||||||||||||||||||||||||||||||||||||||||||||
35: 38 ......................................||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
36: 33 .................................|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
37: 28 ............................||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
38: 24 ________________________||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
39: 19 ...................|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
40: 14 ..............||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
41: 9 .........|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
42: 4 ....||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
43: 0 ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
44: Time: |^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^
45: 12am 1am 2am 3am 4am 5am 6am 7am 8am 9a 10a 11a 12pm 1pm 2pm 3pm 4pm 5pm 6pm 7pm 8pm 9p 10p 11pm
46:
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|