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 = "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.$text = join '', "Average of column 3 for the last ", scalar(@lines), " days: $average\n";
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:
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.my @tmp = split /:/, $lines[-1]; my $last = $tmp[3];
In reply to Re: Re: Re: BASIC MATH WITH DATA
by chipmunk
in thread BASIC MATH WITH DATA
by joachim
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |