Quote:
$text= "Average of column 3 for the last " ; #, scalar (@lines)," days: $average\n";
Originally, that was a print statement, in which the commas were fine. With a scalar assignment, the commas should be replaced with concatenation:
$text = "Average of column 3 for the last " . scalar(@lines) . " days: $average\n";
or with join:
$text = join '', "Average of column 3 for the last ", scalar(@lines), " days: $average\n";
or with a single interpolated string, or with sprintf... There's more than one way to do it.
 

The last line is at @lines[-1]; one way to get the most recent value is: my $last = (split /:/, $lines[-1])[3]; The ( )[3] is called a list slice. It's basically a short way of doing:

my @tmp = split /:/, $lines[-1]; my $last = $tmp[3];
Instead of assigning to the array @tmp and then looking up index 3, the list slice just does the index directly on the list. They give the same results, though, so use whichever is clearer.

In reply to Re: Re: Re: BASIC MATH WITH DATA by chipmunk
in thread BASIC MATH WITH DATA by joachim

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.