HTH#!/usr/bin/perl -w use strict; use warnings; my $sum; my $count; open my $input, '<', 'meres.txt' or die "ERROR: $!\n"; while(my $line = <$input>) { # read line to $li +ne chomp $line; # remove eol if ($line =~ /(-?\d+)/) { # match to numbers + and optional leading minus, the match will be in $1 #print($1."\n"); $sum += $1; # summing up $count++; # count items } } close $input; print 'Average: ', $sum/$count, "\n";
Update:Typo fixed.
In reply to Re: Why this is work?
by pme
in thread Why this is work?
by Csonytii
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |