I am attempting to find the average of an array with this
#usr/bin/perl use strict; use warnings; use List::Util qw(sum); open IN, '<',"part4.csv" or die "can't open input file 'part4.csv': $! +\n"; my $x; my @windsordigits; foreach $x (<IN>){ @windsordigits = ($x =~ /WINDSOR\sRIVERSIDE.*(\d\d?)/); print "@windsordigits\n"; } my $average = sum(@windsordigits) / @windsordigits; print "$average"; close IN;
The issue I am having is that I am getting the "Illegal division by zero line 17, <IN> line 41. The regex only matches line 2-14. I am guessing this issue is occurring because the regex is reading all the way to line 41. Another issue I am having is that when I print out the values it is only printing the first digit and not the second. Am I on the right track here as far as the first issue? And if so is there a way to use the regex on a range of lines so that it doesn't run all the way to line 41. Here is a line from the file I am running it on.
CA006139520,"WINDSOR RIVERSIDE, ON CA",2018-01-02,10
In reply to Illegal division by zero by drose2211
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |