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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.