Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) 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":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2024-04-19 00:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found