G'day programmingzeal,

I've provided some code below; it's in three parts; I don't know how much will be useful for you.

  1. See "Perl core modules". It's worth familiarising yourself with these and avoiding "(sort {$a <=> $b} @values)[0, -1]" and similar.
  2. A conversion changing the origin from top left to bottom left is very straightforward.
  3. The requirements for your graph are unclear. You start talking about an X-Y graph and then seem to be talking about a histogram. I've made a wild guess; it may be a bad one.
#!/usr/bin/env perl use strict; use warnings; use List::Util qw{min max}; # Built-in functions my @values = (7,9,2,0,1,2,4,3,9); print 'Min: ', min(@values), "\n"; print 'Max: ', max(@values), "\n"; print 'Count: ', 0+@values, "\n"; # How to get from (0,0) at top left to bottom left my @matrix = ( [' ' x 2, '*', ' ' x 2], [' ', '*', ' ', '*', ' '], ['*', ' ' x 3, '*'], ); print "\nOriginal:\n"; for (0 .. $#matrix) { print @{$matrix[$_]}, "\n"; } print "\nInverted:\n"; for (reverse 0 .. $#matrix) { print @{$matrix[$_]}, "\n"; } # A complete guess about your graph my @graph; for (0 .. max(@values)) { $graph[$_] = [(' ') x @values]; } for my $i (0 .. $#values) { $graph[$values[$i]][$i] = '*'; } print "\nGraph:\n"; for (reverse 0 .. $#graph) { print @{$graph[$_]}, "\n"; }

Output:

Min: 0 Max: 9 Count: 9 Original: * * * * * Inverted: * * * * * Graph: * * * * * * * * *

For future reference, please avoid unnecessary verbiage: trips down Memory Lane ("I recall my initial programming assignments in Java ..."); merisms ("Pyramid, Square, Rectangle, Circle"); and other irrelevances. Your code has inclusions that are never used: Data::Dumper, $XAxis_LMSE; while missing important parts, such as a print statement. A bit of ASCII art, to demonstrate the type of output you wanted, would have helped greatly.

— Ken


In reply to Re: Plot Graph in Console by printing special character say * and spaces using matrix structure in Perl by kcott
in thread Plot Graph in Console by printing special character say * and spaces using matrix structure in Perl by programmingzeal

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.
  • 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, details, 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, summary, 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.