Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Why this is work?

by pme (Prior)
on May 29, 2018 at 12:52 UTC ( #1215359=note: print w/replies, xml ) Need Help??


in reply to Why this is work?

Hi Csonytii,
#!/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";
HTH

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
    seems a bit cooler code than mine.
    thank you!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2020-10-29 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (266 votes). Check out past polls.

    Notices?