This is a pretty common question, so if you look at the perlfaq docs (specifically see "How can I remove duplicate elements from a list or array" and the next few articles in perlfaq4), it'll show you what you need to know.
Since a hash lets you access a value given a key, you typically do it by first loading your hash with the values you want. As you read the second file, you can check whether the value is in the hash or not.
$ cat t.pl #!/usr/bin/perl use strict; use warnings; my %H = (a=>1, d=>2); while (<DATA>) { s/\s+$//; if (exists $H{$_}) { print "$_ exists in hash\n"; } else { print "$_ missing from hash\n"; } } __DATA__ a b c d
Running this script should give you:
$ perl t.pl a exists in hash b missing from hash c missing from hash d exists in hash
...roboticus
When your only tool is a hammer, all problems look like your thumb.
In reply to Re: How to find the difference between two text files using a hash array
by roboticus
in thread How to find the difference between two text files using a hash array
by NewLondonPerl1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |