#!/usr/bin/perl use strict; use warnings; print graph( @{[1..96]} ); ####################################################################### ### 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 graph { my( $i, $magic, $m, $p, $top, @g ) = ( 0, 20, 7, 96, 0, () ); for (0..$p-1) { $top = $top > $_[$_] ? $top : $_[$_] } my $s = $top > $magic ? ( $top / $magic ) : 1; ### calculate scale for (0..$magic) { $g[$_] = sprintf("%".($m-1)."d ",$_*$s) . ($_%5==0?'_':'.') x $p; for $i (0..$p-1) { substr($g[$_],$i+$m,1) = '|' if $_[$i]/$s>$_ } } join( "\n", reverse( @g ), ' Time: ' . '|^^^' x ( $p / 4 ), ' ' x $m . "12am 1am 2am 3am 4am 5am 6am 7am 8am 9a 10a 11a " . "12pm 1pm 2pm 3pm 4pm 5pm 6pm 7pm 8pm 9p 10p 11pm" ); } # end sub graph __END__ 96 ________________________________________________________________________________________________ 91 ...........................................................................................||||| 86 ......................................................................................|||||||||| 81 .................................................................................||||||||||||||| 76 ............................................................................|||||||||||||||||||| 72 ________________________________________________________________________|||||||||||||||||||||||| 67 ...................................................................||||||||||||||||||||||||||||| 62 ..............................................................|||||||||||||||||||||||||||||||||| 57 .........................................................||||||||||||||||||||||||||||||||||||||| 52 ....................................................|||||||||||||||||||||||||||||||||||||||||||| 48 ________________________________________________|||||||||||||||||||||||||||||||||||||||||||||||| 43 ...........................................||||||||||||||||||||||||||||||||||||||||||||||||||||| 38 ......................................|||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 33 .................................||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 28 ............................|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 24 ________________________|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 19 ...................||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 14 ..............|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 9 .........||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 4 ....|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 0 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Time: |^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^ 12am 1am 2am 3am 4am 5am 6am 7am 8am 9a 10a 11a 12pm 1pm 2pm 3pm 4pm 5pm 6pm 7pm 8pm 9p 10p 11pm