JupiterHost.Net <mailto:[EMAIL PROTECTED]> wrote:

: This will open both files and check each line of file2 against
: each line of file1 (and it alerts you to any problems, is easier
: to read, best pratice safe (hopefully ;p), ect etc):

    Sorry, but it won't. It will open both files and check the
first line of file1 against all the lines of file2. All the rest
of the lines in file1 are not tested. The inner loop only runs
once. The pointer into file2 is never set back to the file start.

    We can test it with this. If each file has four lines in it,
we should see this result.

1234
1234
1234
1234
    
my $i;
while(<$file1_fh>) {

     while(<$file2_fh>) {
                print ++$i;             
     }
     print "\n";
}


: #!/usr/bin/perl
: 
: use strict;
: use warnings;
: 
: open my $file1_fh, '<', 'file1' or die "file1 open failed: $!";
: open my $file2_fh, '<', 'file2' or die "file2 open failed: $!";
: 
: while(<$file1_fh>) {
:      my $line = $_;
:      chomp $line;
: 
:      while(<$file2_fh>) {
:          my $match_against = $_;
:          chomp $match_against;
: 
:          print "Got the string\n" if $line =~ m{$match_against}xms;
:      }
: }
: 
: close $file1_fh;
: close $file2_fh;

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to