Note that there are some explanatory texts on larger screens.

plurals
  1. POTo find the matched and unmatched values in perl
    primarykey
    data
    text
    <p>I am a newbie to programming and I hope someone can explain this to me:</p> <p>So I have two text files i.e. Scan1.txt and Scan2.txt that are stored in my computer. Scan1.txt contains:</p> <pre><code>Tom white black mark john ben </code></pre> <p>Scan2.txt contains:</p> <pre><code>bob ben white gary tom black patrick </code></pre> <p>I have to extract the matched values of these two files and the unmatched values and print them separately. I somehow found the solution for this which works fine. But can someone please explain how exactly the match happens here. Looks like somehow just this line: <code>$hash{$matchline}++</code> in the code does the matching and increments the value of hash when the match is found. I understand the logic but I do not understand how this match actually happens. Can someone help me understand this?</p> <p>Thank you in advance!</p> <p>Here is the code:</p> <pre><code>open (F1, "Scan1.txt"); open (F2, "Scan2.txt"); %hash=(); while ($matchline= &lt;F1&gt; ){ $hash{$matchline}=1; } close F1; while( $matchline= &lt;F2&gt; ){ $hash{$matchline}++; } close F2; foreach $matchline (keys %hash){ if ($hash{$matchline} == 1){ chomp($matchline); push(@unmatched, $matchline); } else{ chomp($matchline); push (@matched, $matchline); } } print "Matched Entries are &gt;&gt;\n"; print "```````````````````````\n"; print join ("\n", @matched) . "\n"; print "```````````````````````\n"; print "Unmatched Entries are &gt;&gt;\n"; print "```````````````````````\n"; print join ("\n", @unmatched) . "\n"; print "```````````````````````\n"; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload