Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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 ( #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? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2023-02-04 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (31 votes). Check out past polls.

    Notices?