Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

count and divide

Posted on 2002-03-13
1
Medium Priority
?
223 Views
Last Modified: 2010-03-05
I've got a plain text file with some random numbers seperated by comma's, like this:

5,6,4,7,5,5,6,9,10,

How can I open the plain text file and count up the numbers and then divide them by the number of numbers ?
(sorry for my bad english)

in the example above I would like to get as result:
6,3 (1 digit behind the comma)
this is 5+6+4+7+5+5+6+9+10 / 9
0
Comment
Question by:oostwijk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 5

Accepted Solution

by:
Sapa earned 200 total points
ID: 6863250
#!/usr/bin/perl -w
use strict;

open(F, '< file.txt') or die $!;
my @digits = <F> =~ /(\d+)/g;
close F;
my $sum = 0;
$sum += $_ for @digits;
print "Result: ", $sum/@digits;
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question