El 23/12/20 a las 1:39, Eli the Bearded escribió:
In comp.lang.perl.misc, gamo <gamo@telecable.es> wrote:
#!/usr/bin/perl -w
use 5.030;
With a simple
use feature qw /say/;
it worked in my older version of perl here.
For "worked" equal to "ran without errors".
No, there were potential errors. Use this version instead.
#!/usr/bin/perl -w
use 5.030;
my @data;
if (@ARGV){
@data = @ARGV;
}else{
@data = split /\s+/, <>;
}
die "Error: Not tput utility" if (length(`which tput`)<3);
my $lines = `tput lines`;
chomp $lines;
$lines--;
my $cols = `tput cols`;
chomp $cols;
$cols--;
if (@data < 3 || @data > $cols){
say "USAGE:";
say "";
say "$0 <data1 data2 ... data$cols>";
say "for printing a simple min-max plot $lines x $cols";
die "TOO FEW POINTS" if @data < 3;
warn "TOO MUCH POINTS" if @data > $cols;
}
my $max = -9e99;
my $min = 9e99;
my $counter = 0;
for my $i (@data){
$counter++;
if (0+$i ne $i) { die "Not numeric $i at point $counter"; }
if ($i <= $min) { $min = $i; }
if ($i >= $max) { $max = $i; }
last if $counter == $cols;
}
die "Error: nothing to plot! (min==max)." if $min == $max;
my $range = $lines/($max-$min);
my @xy;
for my $y (1..$lines){ # MIN-MAX AXIS
$xy[$y][1] = "|";
$xy[$y][$cols+1] = "\n";
if ($y == $lines){
$xy[$y][1] = "+";
for (2..$cols) { $xy[$y][$_] = "-"; }
}
}
my %h;
for my $x (1..$counter){
$h{ $data[$x-1] } = 1+ int ( ( $max-$data[$x-1] ) * $range );
$xy[ $h{ $data[$x-1] } ][$x] = "0";
}
for my $y (1..$lines){
for my $x (1..$cols+1){
if (defined $xy[$y][$x]){
print $xy[$y][$x];
}else{
if ( $y % 20 == 0 && $x % 40 == 0 ){
print "·";
}else{
print " ";
}
}
}
}
exit 0;
__END__
Simple min-max plot in xterm
Simple min-max plot in xterm
Maybe I'm being simple, but I can't figure out what I would use this
for. I don't really understand what it is trying to plot.
The evolution of relative data in a serie,
printed in a single screen that says
"more or less this data is about this".
$ perl5.24 perlutil 19 34 51 77
| 0
|
|
|
|
|
|
|
|
|
| 0
|
|
|
|
|
|
|0
|
| ·
|
| +------------------------------------------------------------------------------
$
What exactly am I looking at here?
Well 19 34 51 77 is more or less
+19 +15 +17 +26
so that is what you see in a single pass view.
(And if you want to use Unicode for graphing, have you considered the
Braille characters? U+2800 (no dots) to U+28FF (two columns of four
dots). The order is a little odd, since "six dot" Braille is more common
than "eight dot", so the "low dot" ones come after all the others.
U+283F ⠿ all six dots of the common encoding, U+28C0 ⣀ the two low dots, U+28FF ⣿ all eight dots. Sequence for a loading loop in text:
⣷ ⣯ ⣟ ⡿ ⢿ ⣻ ⣽ ⣾ )
Elijah
------
https://qaz.wtf/u/grep.cgi?grep=braille
Yes, great!...
if I know how to use unicode in a similar fashion of the way
people used the 0..255 ascii + extended chars table of code,
when a box was a real box and not like
+-+
| |
+-+
(which happens to be now perfectly fine to me because I think is
the compatible and "safe" way of displaying a box).
Thanks a lot.
--
http://gamo.sdf-eu.org/
"What happens in EuroVegas it remains in EuroVegas"
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)