in reply to Re: Re: BASIC MATH WITH DATA
in thread BASIC MATH WITH DATA
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];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: BASIC MATH WITH DATA
by joachim (Initiate) on Jan 26, 2001 at 04:40 UTC | |
by tye (Sage) on Jan 26, 2001 at 07:09 UTC | |
by joachim (Initiate) on Jan 26, 2001 at 08:34 UTC | |
by tye (Sage) on Jan 26, 2001 at 09:39 UTC |