Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Matching 2 unordered arrays then printing the first array highlighting the matches?

by Old_Gray_Bear (Bishop)
on Oct 28, 2013 at 19:40 UTC ( [id://1060051]=note: print w/replies, xml ) Need Help??


in reply to Matching 2 unordered arrays then printing the first array highlighting the matches?

Dear DT --

First method (non-Perl):

  1. sort fileA and write it to /tmp
  2. sort fileB and write it to /tmp
  3. Use cmp or diff to detect the differences between the two /tmp files and report.
Second Method (using Perl):
  1. read fileA and use each value as a hash-key with a hash-value of 1 ($seen_hash{$valueA} = 1;)
  2. read fileB and use each value as a hash-key and add a value of 2 ($seen_hash{$valueB} += 2;)
  3. Read through the hash and report on all keys where the value is '3'.

----
I Go Back to Sleep, Now.

OGB

  • Comment on Re: Matching 2 unordered arrays then printing the first array highlighting the matches?
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Matching 2 unordered arrays then printing the first array highlighting the matches?
by hdb (Monsignor) on Oct 28, 2013 at 21:19 UTC

    What happens if there are duplicates in fileB?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-25 04:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found