Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: rearrange data to min, avg, max

by cyocum (Curate)
on Apr 30, 2004 at 16:07 UTC ( #349441=note: print w/ replies, xml ) Need Help??


in reply to rearrange data to min, avg, max

Based on the data you have shown. I wrote the code below. However, please be warned that I wrote this off the top of my head and it may not work or even do what I purport it to do.

use strict; use warnings; my @array; my @values; my $avg; while(my $line = <DATA>) { push @array, $line; } foreach my $line2 (@array) { my ($time, $val, $err) = split / /, $line2; push @values, $val; my $tot_val += $val; $avg = $tot_val / $#array; } my @sort_max = sort {$a <=> $b} @values; my @sort_min = soft {$b <=> $a} @values; my $max_val = pop @sort_max; my $min_val = pop @sort_min; foreach my $line3 (@array) { my ($time, $val, $err) = split / /, $line3; if($val == $max_val) { print "max: $line3" . "\n"; } elsif($val == $min_val) { print "min: $line3" . "\n"; } } print "avg: $avg" . "\m"; __DATA__ 04/26/04.16:15 3.088 N 04/26/04.16:15 5.994 N 04/26/04.16:15 4.391 N 04/26/04.16:15 3.616 N 04/26/04.16:20 3.997 N 04/26/04.16:20 4.151 N 04/26/04.16:20 3.751 N 04/26/04.16:20 2.887 N 04/26/04.16:25 3.657 N 04/26/04.16:25 4.712 N 04/26/04.16:25 4.346 N 04/26/04.16:30 3.628 N 04/26/04.16:30 5.636 N 04/26/04.16:30 4.593 N


Comment on Re: rearrange data to min, avg, max
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2015-07-29 05:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls