CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Compare 2 Files

 



commander
New User

Jul 19, 2012, 5:17 AM

Post #1 of 3 (6246 views)
Compare 2 Files Can't Post

Hi guys,

I'm just trying to compare two files. Both files have only one word per line.
The differences of both files should stored in another file.
I have it already tryed and it looks like this:

Code
use strict;  
use warnings;
use Text::Diff;
use Class::CSV;


open(FILE, ">/home//Documents/Compare/diff.csv") or die "Cannot open file";
my $diffs = diff '/home//Documents/Compare/prtg.csv' => '/home//Documents/Compare/linuxserver.csv';

print $diffs;
print FILE "$diffs";

close(FILE);

The output is not the different of both files. It contains all Word of both Files.


Zhris
Enthusiast

Jul 19, 2012, 6:40 PM

Post #2 of 3 (6226 views)
Re: [commander] Compare 2 Files [In reply to] Can't Post

Hi,

Your code works fine for me / based on my example input files.

Input1

Code
hello 
hi
bye
cya


Input2

Code
hello 
hiya
byeee
cya


Output

Code
--- one.txt	Fri Jul 20 02:23:22 2012 
+++ two.txt Fri Jul 20 02:23:32 2012
@@ -1,4 +1,4 @@
hello
-hi
-bye
+hiya
+byeee
cya


Which is effectively "all Word of both Files". Are you not receiving a similar output. If you are, what is the output you desire.

Chris


(This post was edited by Zhris on Jul 19, 2012, 6:49 PM)


BillKSmith
Veteran

Jul 23, 2012, 8:43 PM

Post #3 of 3 (5941 views)
Re: [commander] Compare 2 Files [In reply to] Can't Post

Refer to the FAQs: perldoc -q "difference between two arrays"
Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives