Dear All, I need a help to add a feature to my perl script. the script takes as input a file & finds the maximum & minimum value of it. Based on the min and max value you can defined the scale by using the bin size. (user input) For example bin size is 30 and min -100ps max 100ps then the scale to be -100 to -80, -80 to -60, -60 to -40, -40 to -20, -20 to 0, 0 to 20, 20 to 40, 40 to 60, 60 to 80, 80 to 100 Count the number of points falling in the scale range and display the file similar as shown below.
-60 < x <= -30 ( 6273 pts) |** -30 < x <= 0 ( 44623 pts) |******** 0 < x <= 30 ( 55626 pts) +********** 30 < x <= 60 ( 11244 pts) |**
please find the code below,
my $file = $ARGV[0]; # input file my $bin = $ARGV[1]; # bin size normally 20 or 30 my $outfile = "temp.stat"; open (IN_LOG,"$file") || die "cannot open $file for reading: $!"; open (OUT_LOG,">$outfile") || die "cannot open $outfile for writing: $ +!"; my $colName; my @array; while (<IN_LOG>) { push (@array,$_); } } my @sortArray = sort { $a <=> $b } @array; $max = $sortArray[-1]; $min = $sortArray[0]; print OUT_LOG "#- - - - - - - - - - - - - - - - - - - - -\n"; print OUT_LOG "#MAX : $max \n"; print OUT_LOG "#MIN : $min \n"; print OUT_LOG "#- - - - - - - - - - - - - - - - - - - - -\n"; $temp=$max-$bin; while ($max>=$min) { $i=0; print OUT_LOG "\n$max > $bin < $temp:"; foreach $val (@array) { if($val<=$max && $val>=$temp) { $i+=1; } } $max= $temp; $temp=$temp-$bin; print OUT_LOG " $i pts "; my $star = int($i/500) + 0.5; $var= '*' x $star; print OUT_LOG "| $var\n "; } close IN_LOG; close OUT_LOG; close MYFILE;
currently i am able to sort the array & find the maximum & minimum values but not able to generate the scale/chart as shown above. the sampe of input file will be (as it is a huge file)
45.980 -34.99 89.00 35.87 75.00 -30.173 -40.178
thanks.

In reply to generate a chart using the data 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!
  • 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.