Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: comparing 2 columns

by kikuchiyo (Hermit)
on Jan 04, 2016 at 19:52 UTC ( [id://1151863]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1151863]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2024-04-23 09:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found