in reply to How do I select first string of a two dimensional array to compare to other values?
Here is an example using the first line of data compared to the other values. Note, it skips lines containing ! which may precede the first data line
#!/usr/bin/perl use strict; use warnings; my $file = $ARGV[0]; open (RAW, '<', "./$file") or die "Can't open $file for read: $!"; my @first; my $line_count = 0; while (<RAW>){ chomp; next if /!/; my @col = split /,/,$_; if (++$line_count == 1){ @first = @col; print "\n--------------------------------\n"; print "Start $first[1]\n"; print sprintf "%10s %10s %10s\n",'+secs','value','change'; print sprintf "%10s %10s %10s\n",'-'x10,'-'x10,'-'x10; } print sprintf "%10d %10.3f %10.3f\n", ($col[0] - $first[0]), $col[2], ($col[2] - $first[2]); }
Outputs
poj-------------------------------- Start 2015-02-22 16:15:00 +secs value change ---------- ---------- ---------- 0 4294.700 0.000 60 4289.700 -5.000 120 4299.800 5.100 180 4302.800 8.100 240 4296.900 2.200 300 4301.000 6.300 360 4300.300 5.600
|
|---|