I can see a number of things wrong here:
- You aren't actually iterating over anything. Try 'while(<FILE1>)' rather than just 'while()'.
- The second filehandle won't reset on each iteration of the outer loop. Try slurping the data into an array / hash instead.
- You didn't use code tags. Try reading the FAQ.
Here's a quick example of a better way to do this:
#!/usr/bin/perl -w
use strict;
open(FILE1,"/tmp/file1") or die "Couldn't open /tmp/file1: $!";
open(FILE2,"/tmp/file2") or die "Couldn't open /tmp/file2: $!";
my @array;
my %hash;
while (<FILE1>) {
chomp;
push @array, $_;
}
while (<FILE2>) {
chomp;
$hash{$_} = '';
}
close FILE1;
close FILE2;
foreach (@array) {
if(exists $hash{$_}) {
print "$_ matched!\n"
}
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|