1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
use warnings; use strict; use Statistics::Descriptive; open (INFILE, '<wwertenewgene.txt') or die "Opening input file failed: $!\n"; open (OUTFILE, '>TEST.txt'); #my $linenumber = 0; while (<INFILE>) { foreach (/start/../end/) { my @gene = $_; next if /start/||/end/; print OUTFILE "@gene"; # if (<INFILE> =~ m/final/ ){last;} # do # { # print "$linenumber";$linenumber++; # } # until ($newgene =~m/newgene/); } # print OUTFILE "hallo\n"; } #print 'Geometrischer Mittelwert: ', #$stat->geometric_mean(), "\n";
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#! /usr/bin/perl use strict; use warnings; use List::Util qw( sum ); my @values; while ( my $line = <DATA> ) { if ( $line =~ m{^start$} ... $line =~ m{^end$} ) { if ( $line !~ m{^(?:start|end)$} ) { push @values, $line; } elsif ( $line =~ m{^end$} ) { # einfacher Mittelwert my $average = sum(@values)/@values; print $average, "\n"; # reset for next dataset @values = (); } } } __DATA__ start 0.23 0.32434 0.234 1.0 end start 0.3423 1.4 end final
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#! /usr/bin/perl use strict; use warnings; use List::Util qw( sum ); my @values; { # jeweils blockweise einlesen bis zum "end\n" local $/ = "end\n"; while ( my $dataset = <DATA> ) { my @values = grep { m{^[\d.]+$} } split m{\n}, $dataset; next if !@values; my $average = sum(@values)/@values; print $average, "\n"; } } __DATA__ start 0.23 0.32434 0.234 1.0 end start 0.3423 1.4 end final
2012-12-11T18:41:29 Linuxer
use Statistics::Descriptive;
1 2 3
my $stat = Statistics::Descriptive::Full->new(); $stat->add_data(@values); print "geometric_mean: ", $stat->geometric_mean(), "\n";