in reply to Re^2: 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?

So how does your current code fail to serve your purposes? An alternative:

c:\@Work\Perl\monks>perl -wMstrict -le "my $line = qq{1424621700, 2015-02-22 16:15:00, 4294.700\n}; chomp $line; print qq{'$line'}; ;; my ($first) = split m{ , \s* }xms, $line; print qq{'$first'}; " '1424621700, 2015-02-22 16:15:00, 4294.700' '1424621700'

Update: Ah, I see it now:
    my $first_line = $splits;
and again, how can this compile with strict enabled? You probably want something like the
    my $first_line = $splits[0];
statement you had before.


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

  • Comment on Re^3: 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^4: How do I select first string of a two dimensional array to compare to other values?
by joi1369 (Initiate) on Aug 31, 2015 at 01:19 UTC

    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

      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:  <%-{-{-{-<

      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:  <%-{-{-{-<