Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: No-Frills Curve Sketches

by YuckFoo (Abbot)
on Jul 06, 2004 at 23:06 UTC ( [id://372230]=note: print w/replies, xml ) Need Help??


in reply to No-Frills Curve Sketches

Here is my graph program. Reads from STDIN and splits on whitespace. The first field is the label and the second field gets plotted. You did say no frills right?

YuckFrill

Example:

perl -e 'print "$_ " . sin($_ / 10) . "\n" for (1..64)' | graph.pl
#!/usr/bin/perl use strict; my ($WIDE) = @ARGV; $WIDE ||= 80; my (@list, $min, $max); my ($maxval, $maxkey); while (my $line = <STDIN>) { chomp $line; my ($key, $val) = split(' ', $line); if (defined($key) && defined($val)) { push (@list, { key => $key, val => $val}); if (!defined($min) || $val < $min) { $min = $val; } if (!defined($max) || $val > $max) { $max = $val; } if (!defined($maxkey) || length($key) > $maxkey) { $maxkey = length($key); } if (!defined($maxval) || length($val) > $maxval) { $maxval = length($val); } } } my $factor = ($max - $min) / ($WIDE - $maxkey - $maxval - 2); for my $i (@list) { printf STDOUT "%-*.*s %s $i->{val}\n", $maxkey, $maxkey, $i->{key}, '*' x (($i->{val} - $min) / $factor +); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://372230]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2024-03-29 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found