in reply to Unscalar'ize a fake array
Hello Gtforce,
As 1nickt says, you need to determine the exact form of the data. Assuming it is a single string, with each “element” on a different line, you will need to split it on newlines to get a list of elements; then, for each element, you’ll need to split again, this time on whitespace, to break the line into its component fields. For example:
use strict; use warnings; my $result = '2017-08-01 20MICRONS 37744 2016-08-01 20MICRONS 25966 2016-04-20 20MICRONS 30807 2016-04-01 20MICRONS 32780'; my @results = split /\n/, $result; my $total; print "CHECKPOINT\n"; for my $element (@results) { print "$element\n"; my @fields = split /\s+/, $element; $total += $fields[2]; } printf "Average: %.1f\n", ($total / scalar @results);
Output:
22:47 >perl 1821_SoPW.pl CHECKPOINT 2017-08-01 20MICRONS 37744 2016-08-01 20MICRONS 25966 2016-04-20 20MICRONS 30807 2016-04-01 20MICRONS 32780 Average: 31824.2 22:47 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Unscalar'ize a fake array
by Gtforce (Sexton) on Sep 22, 2017 at 02:23 UTC |