use strict; use warnings; use List::Util qw(min max); # Simple plotting re: node_id=11146802 use constant MAXLINES => 200; #Abort if more than 200 lines in printout # @inData is the input data to plot # A 2-D array of pairs (#iterations, value) # # Valid #iterations are integers. The graph will take # maxiter-miniter+1 lines to display. # The zero is suppressed. # Valid data values are in the range of 0.0-10.0 in 0.1 increments # or rather 101 characters from left of screen to the right # indicies [0..100] my @inData = ([200,3.5],[220,5.8],[210,6.5]); my @col1 = map{$_->[0]}@inData; #just extracts col1 as simple array my $min_iter = min (@col1); #these funcs are faster than a sort my $max_iter = max (@col1); print "minimum iter=$min_iter ; maximum iter= $max_iter\n"; #you decide what you want here... die "Too many lines required! ABORT!" if ($max_iter-$min_iter+1 > MAXLINES); my @Plot; #initialize Plot Matrix # "burns" some memory at beginning of array to avoid a linear # "offset" adjustment factor # $Plot[$_]=" " x 101 for ($min_iter..$max_iter); foreach my $row_ref (@inData) { my ($n_iter, $data) = @$row_ref; plot_point ($n_iter, $data,1); #can turn FILL OFF if desired } dumpPlot(); ############ sub plot_point { my ($n_iters, $data, $fill) = @_; $fill //= 0; #fill defaults to none my $height = get_height($data); # height range 0 - 100 die "Data Value $data out of range" if ($height > 100); ## you decide what to do substr($Plot[$n_iters],$height,1) = '*'; if ($fill) { substr($Plot[$n_iters],$_,1)= '*' for (0..$height-1); #don't need a loop but #this was easier } } sub get_height #converts for example: 8.4543 to 85 { my $value = shift; my $rounded_value = sprintf("%.1f",$value); #.1 precision #changed fmt spec to f (duh!) return ($rounded_value * 10); } sub dumpPlot { print "$Plot[$_]\n" for ($min_iter..$max_iter); } __END__ note lines truncated (not full 101 characters). minimum iter=200 ; maximum iter= 220 ******************************* ************************************************************* ***************************************************