I receive an array @result, which is my starting point. I think it is an array, but when I run this snippet of code to test the data that is in the array, it would appear that there's a scalar sitting in it. My end-purpose is to calculate the average of the last column, but can't figure out how. Any help is appreciated, thanks.

my $counter=0; foreach my $element (@result) { print "\nCHECKPOINT\n $result[$counter]\n"; $counter ++; }

Result:

CHECKPOINT

2017-08-01 20MICRONS 37744

2016-08-01 20MICRONS 25966

2016-04-20 20MICRONS 30807

2016-04-01 20MICRONS 32780

UPDATE: I don't mean to prolong this thread, but hopefully a quick question. My data set is about 100Mb with about 2k records and consequently ((2k-n)*n) loops, 'n' being my averaging period (loops because I'm doing a moving average to smoothen the data series). I tested my data set using a "WHILE", and then using a "FOREACH" (the 2 suggestions that were provided on this thread). Looping via foreach costs me less than a second, whilst looping via while costs several seconds (~5 seconds). I'm new to perl and am wondering if that's how it is meant to be, and consequently, what would be my use case for 'while'.

foreach (<myarray>) { my @dataset = split /blah/, $myarray[$outercounter]; for ($innercounter = 0; $innercounter < n; $innercounter++) { my $counter = $innercounter + $outercounter; my @miniarray = split /blah/, $myarray[$counter]; $sum += $miniarray[x]; } $outercounter ++; my $mavg = $sum / n; push (@resultset, "the things I need"); $sum = 0; $mavg = 0; last if $outercounter == scalar(@myarray); }

In reply to Unscalar'ize a fake array by Gtforce

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.