From: Subhash on
Hi

Im comparing two files. Newer file has blank-line introduced at the
end. So the file difference is only a blank-line at the end. If I need
to ignore this difference, module File::Compare does not help.

tried with the third argument to the cmp function:
cmp("file1","file2", sub { chomp($_[0]) ne chomp($_[1]) })
which would chomp the lines and then compare the difference if any.
But still there is difference.

Can you please let me know where Im making the mistake.

Thanks
Subhash
From: Subhash on
On Mar 2, 5:32 pm, Subhash <subhas...(a)gmail.com> wrote:
> Hi
>
> Im comparing two files. Newer file has blank-line introduced at the
> end. So the file difference is only a blank-line at the end. If I need
> to ignore this difference, module File::Compare does not help.
>
> tried with the third argument to the cmp function:
>   cmp("file1","file2", sub { chomp($_[0]) ne chomp($_[1]) })
> which would chomp the lines and then compare the difference if any.
> But still there is difference.
>
> Can you please let me know where Im making the mistake.
>
> Thanks
> Subhash

tweaked a bit, added chomp to a subroutine:
sub trim($) {
my $line = $_[0];
chomp($line);
return $line;
}
my $result = cmp("file1","file2", sub {trim $_[0] ne trim $_[1]});

but still the comparison fails
From: ccc31807 on
On Mar 2, 7:32 am, Subhash <subhas...(a)gmail.com> wrote:
> Im comparing two files. Newer file has blank-line introduced at the
> end. So the file difference is only a blank-line at the end.

Tie::File lets you treat a file like an array. You might pop the last
line of the file you are treating like an array. I'll try this later
on in the day when I get a break and post back.

CC.
From: Uri Guttman on
>>>>> "S" == Subhash <subhash12(a)gmail.com> writes:

S> On Mar 2, 5:32�pm, Subhash <subhas...(a)gmail.com> wrote:
>>
>> Im comparing two files. Newer file has blank-line introduced at the
>> end. So the file difference is only a blank-line at the end. If I need
>> to ignore this difference, module File::Compare does not help.
>>
>> tried with the third argument to the cmp function:
>> � cmp("file1","file2", sub { chomp($_[0]) ne chomp($_[1]) })
>> which would chomp the lines and then compare the difference if any.
>> But still there is difference.

how are you getting the cmp() function into your code? are you
explicitly importing it? from the module docs:

File::Compare::cmp is a synonym for File::Compare::compare. It is
exported from File::Compare only by request.

use the longer name as you may be getting the builtin cmp op instead.

S> tweaked a bit, added chomp to a subroutine:
S> sub trim($) {
S> my $line = $_[0];
S> chomp($line);
S> return $line;
S> }

are you sure the blank line only has a newline in it? you need to check/trim
all trailing white space if it isn't just a newline.

S> my $result = cmp("file1","file2", sub {trim $_[0] ne trim $_[1]});

have you run the unix diff command and seen that is the only difference?
how do you know it is only a trailing blank line that is the failing
diff?

uri

--
Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: Subhash on
On Mar 2, 7:56 pm, "Uri Guttman" <u...(a)StemSystems.com> wrote:
> >>>>> "S" == Subhash  <subhas...(a)gmail.com> writes:
>
>   S> On Mar 2, 5:32 pm, Subhash <subhas...(a)gmail.com> wrote:
>   >>
>   >> Im comparing two files. Newer file has blank-line introduced at the
>   >> end. So the file difference is only a blank-line at the end. If I need
>   >> to ignore this difference, module File::Compare does not help.
>   >>
>   >> tried with the third argument to the cmp function:
>   >> cmp("file1","file2", sub { chomp($_[0]) ne chomp($_[1]) })
>   >> which would chomp the lines and then compare the difference if any..
>   >> But still there is difference.
>
> how are you getting the cmp() function into your code? are you
> explicitly importing it? from the module docs:
>
>         File::Compare::cmp is a synonym for File::Compare::compare.  It is
>         exported from File::Compare only by request.
>
> use the longer name as you may be getting the builtin cmp op instead.
>
>   S> tweaked a bit, added chomp to a subroutine:
>   S> sub trim($) {
>   S>         my $line = $_[0];
>   S>         chomp($line);
>   S>         return $line;
>   S> }
>
> are you sure the blank line only has a newline in it? you need to check/trim
> all trailing white space if it isn't just a newline.
>
>   S> my $result = cmp("file1","file2", sub {trim $_[0] ne trim $_[1]});
>
> have you run the unix diff command and seen that is the only difference?
> how do you know it is only a trailing blank line that is the failing
> diff?
>
> uri
>
> --
> Uri Guttman  ------  u...(a)stemsystems.com  --------  http://www.sysarch.com--
> -----  Perl Code Review , Architecture, Development, Training, Support ------
> ---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com---------

CC, presently have read the entire file into an array and removing
blank-lines from the last.

Yes Uri, have explicitly imported cmp of File::Compare module.
ran diff under UNIX, it showed the difference in the last line only.
(ie) the blank line

Thanks
Subhash