Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (7)
    As of 2015-07-06 09:33 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (71 votes), past polls