in reply to comparing 2 columns

This should do what you want:

#!/usr/bin/perl # http://perlmonks.org/?node_id=1151834 use strict; use warnings; open my $FH1, '<', shift or die $!; my %keys; while (<$FH1>) { chomp; $keys{$_}++; } close $FH1; open my $FH2, '<', shift or die $!; while (<$FH2>) { chomp; my ($record, $key) = split ',', $_, 2; print "match: $key record: $record\n" if exists $keys{$key}; } close $FH2;

Your code looks like something you've copied from somewhere without really understanding it. I'd advise against doing that: cargo cult code like that might be inefficient, might not actually do what you want, or it might even do damage to your system or data without you knowing it.

Replies are listed 'Best First'.
Re^2: comparing 2 columns
by 2015_newbie (Novice) on Jan 05, 2016 at 05:09 UTC
    It works just great! Thanks so much! I tried to see how it works and it appears that in this line: print "match: $key record: $record\n" if exists $keys{$key}; $key holds the value of the second and third columns and record holds the first column. what is this: my ($record, $key) = split ',', $_, 2; the split is for the comma but what is the 2? Is that for 2 columns? Not sure -can you explain? I have been reading Alvin Alexander tutorial on hash but I am still green.
      ... split ... what is the 2?

      Please see split documentation,  LIMIT in particular.


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