LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux > Linux - Newbie
User Name
Password
Linux - Newbie This 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

Tags used in this thread
Popular LQ Tags ,

Reply
 
Thread Tools
Old 10-14-2009, 04:46 PM   #1
Phred_42
LQ Newbie
 
Registered: Oct 2009
Posts: 2
Thanked: 0
Unhappy Problems in using DIFF in PERL


[Log in to get rid of this advertisement]
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..
windows_xp_2003 Phred_42 is offline  
Tag This Post ,
Reply With Quote
Old 10-14-2009, 04:55 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :}
Posts: 18,844
Blog Entries: 1
Thanked: 160
Hi,

welcome to LQ!

Did you see this thread ?


Cheers,
Tink
linux Tinkster is online now     Reply With Quote
Old 10-14-2009, 07:05 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 5.4
Posts: 7,419
Thanked: 325
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
windows_xp_2003 chrism01 is offline     Reply With Quote
Old 10-15-2009, 10:56 AM   #4
Phred_42
LQ Newbie
 
Registered: Oct 2009
Posts: 2
Thanked: 0

Original Poster
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
windows_xp_2003 Phred_42 is offline  
Tag This Post ,
Reply With Quote
Old 10-15-2009, 08:13 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 5.4
Posts: 7,419
Thanked: 325
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
windows_xp_2003 chrism01 is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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 02:13 AM.

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration