LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 10-14-2009, 04:46 PM   #1
Phred_42
LQ Newbie
 
Registered: Oct 2009
Posts: 2

Rep: Reputation: 0
Unhappy Problems in using DIFF in PERL


I'm learning PERL and writing production code at the same time, not fun. I am currently comparing directories using "diff -r file1 file2" In a manual mode, this works great. but not so good when it is installed into a PERL program -

----------------------------------------------------------------
$DiffLocation="/DIR1/Parent/";

print "Name of listing: ";
my $DataFile=<STDIN>;
chomp $DataFile;

my $DataName=$DiffLocation.$DataFile."\.txt";
my $DiffName=$DiffLocation.$DataFile."_Output\.txt";


open(DATANAME,"<$DataName") or die("Unable to open $DataName \n");
open(DIFFNAME,">$DiffName") or die("Unable to open $DiffName \n");


while (<DATANAME>)
{
my $DataList=$_;
my @DataString=split(/\t/,$DataList);
chomp @DataString;

print "Comparing entries $DataString[0]: $DataString[1] and $DataString[2] \n";
print DIFFNAME $DataString[1] $DataString[2];
`diff -r $DataString[1] $DataString[2] >> $DiffName`;

}
close(DIFFNAME);
close(DATANAME);

-----------------------------------------------------------------

What I get for a typical data set consisting of
Order : Dir Path 1 : Dir Path 2
------------------------------------------------------------
1 : /DIR9/ParentNew/Child1 : /DIR8/Docs/ParentOld/Child1
2 : /DIR9/ParentNew/Child2 : /DIR4/Docs/ParentOld/Child2

is -

omparing entries 1: /DIR9/ParNew/Child1 /DIR8/Docs/ParOld/Child1
: No such file or directoryOld/Child1
omparing entries 2: /DIR9/ParNew/Child2 /DIR4/Docs/ParOld/Child2
: No such file or directoryOld/Child2

Note that 21 of the lead characters of the second directory path disappear in the actual process. An of course no needed output has resulted. In addition, I also somehow manage to lose the leading letter or number in each outputted row so that the C of Comparing does not show.

Any ideas as to where I've gone wrong?

Last edited by Phred_42; 10-14-2009 at 04:53 PM.
 
Old 10-14-2009, 04:55 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,004
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Hi,

welcome to LQ!

Did you see this thread ?


Cheers,
Tink
 
Old 10-14-2009, 07:05 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Id that really the actual code & input & output, because they don't seem to match up:
Code:
1 : /DIR9/ParentNew/Child1 : /DIR8/Docs/ParentOld/Child1
has 3 ':', yet none of them appear in the output, in spite of the fact you split on tabs.

Are the tabs at the start of each dirpath? It would be much better if you showed the input/code/output inside LQ code tags..
The missing C is probably because you have an invisible ctrl char (a 'del') at the start there. Just manually delete the 1st 3 chars of "Comparing" and re-insert carefully.

Also, the word 'and' in your code
Code:
print "Comparing entries $DataString[0]: $DataString[1] and $DataString[2] \n";
is entirely absent from the output.

Show us the real stuff.

Also, always start all Perl progs with warnings and strict modes on:

#!/usr/bin/perl -w
use strict;

http://perldoc.perl.org/
http://www.perlmonks.org/?node=Tutorials
 
Old 10-15-2009, 10:56 AM   #4
Phred_42
LQ Newbie
 
Registered: Oct 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Sorry for the :'s

Some actual input -
1 /images10/CN/cn000161-03c /images02/Docs/AR0003S3/cn000161-03c
2 /images10/CN/cn000161-04c /images02/Docs/AR0003S3/cn000161-04c

Did the delete and re-entry thing for Comparing and got back the C.

Added use strict; , had to change the first declaration -
$DiffLocation="/DIR1/Parent/"; to my $DiffLocation="/DIR1/Parent/";

Also added - my $ShowDir = "$DataString[1] and $DataString[2]";
so that - print DIFFNAME $ShowDir; works.

However, I still get the actual error messages -
Comparing entries 1: /images10/CN/cn000161-03c and /images02/Docs/AR0003S3/cn000161-03c
: No such file or directoryS3/cn000161-03c
Comparing entries 2: /images10/CN/cn000161-04c and /images02/Docs/AR0003S3/cn000161-04c
: No such file or directoryS3/cn000161-04c
 
Old 10-15-2009, 08:13 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Can you just post the new code (in code tags ), it's easier than me imagining it? The devil is in the details.
Also, post the data in code tags and specify (add notes) explaining where we've got tabs or spaces.
Thx
 
  


Reply

Tags
diff, perl


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with patch file creation using svn diff and fold lgp171188 Linux - General 1 08-28-2009 12:49 PM
problems with perl.. amachine7 Mandriva 2 01-02-2005 04:25 PM
Perl problems gharvey Linux - Newbie 8 12-21-2004 08:21 AM
Dual Boot diff Hard Disk diff OS on Suse 9.1 wilhem Linux - Newbie 1 08-13-2004 07:06 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 09:09 PM


All times are GMT -5. The time now is 11:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration