in reply to Why this is work?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2:Why this is work?
by Csonytii (Novice) on May 29, 2018 at 13:19 UTC |