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

-------------------------------- 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
poj

In reply to Re: How do I select first string of a two dimensional array to compare to other values? by poj
in thread How do I select first string of a two dimensional array to compare to other values? by joi1369

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.