Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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 chilling in the Monastery: (4)
As of 2019-11-14 06:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (76 votes). Check out past polls.

    Notices?