Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: reading lines from 2 different files

by toolic (Bishop)
on Oct 08, 2007 at 15:44 UTC ( [id://643488]=note: print w/replies, xml ) Need Help??


in reply to reading lines from 2 different files

If you want to compare all lines of the 2 files, just like the unix "diff" command (or "tkdiff"):
use warnings; use strict; open my $fh1, '<', 'file1.txt' or die "Can not open file1.txt $!\n"; open my $fh2, '<', 'file2.txt' or die "Can not open file2.txt $!\n"; while (<$fh1>) { chomp; my $line_f2 = <$fh2>; chomp $line_f2; if ($_ ne $line_f2) { print "Mismatch at line $.\n"; print "file1: $_, file2: $line_f2\n"; } } close $fh2; close $fh1;

Replies are listed 'Best First'.
Re^2: reading lines from 2 different files
by ikegami (Patriarch) on Oct 08, 2007 at 18:58 UTC
    Your code silently ignores extra lines in file2.
      Yes, I realize that, but thanks for explicitly pointing it out. The OP stated that the 2 files have the "same number of lines". So, I presumed that the OP would be checking that ahead of time.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://643488]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-03-29 00:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found