in reply to Re^3: How do I select first string of a two dimensional array to compare to other values?
in thread How do I select first string of a two dimensional array to compare to other values?

Rather than printing out only 1424621700, it prints out the entire first column like so-

1424621700 1424621760 1424621820 1424621880 1424621940 1424622000 1424622060 1424622120 1424622180 1424622240 1424622300

Again, thank you so much for the help

  • Comment on Re^4: How do I select first string of a two dimensional array to compare to other values?
  • Select or Download Code

Replies are listed 'Best First'.
Re^5: How do I select first string of a two dimensional array to compare to other values?
by AnomalousMonk (Archbishop) on Aug 31, 2015 at 01:49 UTC

    Or perhaps you mean that you want to compare the first field of the first line in the file against the first fields of all subsequent lines? In that case, perhaps something like (also untested):

    ... open file handles, etc. ... defined(my $first_line = <RAW>) or die "reading raw input: $!"; chomp $first_line; my ($first_line_first_field) = split m{ , \s* }xms, $first_line; while (defined(my $following_line = <RAW>)) { chomp $following_line; my ($following_line_first_field) = split m{ , \s* }xms, $following +_line; compare($first_line_first_field, $following_line_first_field); } close RAW or die "closing raw handle: $!";
    (Of course, you have to write the  compare() function!)

    Update: Added error check to original
        my $first_line = <RAW>;
    statement above to make it
        defined(my $first_line = <RAW>) or die "reading raw input: $!";


    Give a man a fish:  <%-{-{-{-<

Re^5: How do I select first string of a two dimensional array to compare to other values?
by AnomalousMonk (Archbishop) on Aug 31, 2015 at 01:30 UTC

    But your code above loops through the entire file of the  RAW input handle (assuming the syntax error is fixed), processing and printing every line. (BTW: Nothing is ever written to the  OUT handle.)

    If you want to process only the first line of RAW, maybe something like (untested):

    my $first_line = <RAW>; close RAW or die "closing raw input: $!"; chomp $first_line; my $first_field = split m{ , \s* }xms, $first_line; print "$first_field\n";


    Give a man a fish:  <%-{-{-{-<