Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Array::Compare issues

by BrowserUk (Patriarch)
on Oct 03, 2003 at 19:50 UTC ( [id://296374]=note: print w/replies, xml ) Need Help??


in reply to Array::Compare issues

The output from full_compare() in a list context is a list of indices of elements that differ. To retrieve that actual values, use the returned list to index into the original arrays.

print "line $_ differs. File 1: $file1[ $_ ] != File 2: $file2[ $_ ]\n +" for $comp->full_compare(\@file1,\@file2);

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.

Replies are listed 'Best First'.
Re: Re: Array::Compare issues
by sunadmn (Curate) on Oct 03, 2003 at 20:05 UTC
    Great I will try that.
Re: Re: Array::Compare issues
by sunadmn (Curate) on Oct 03, 2003 at 20:09 UTC
    Ok so we tried that and we are getting this now:
    Use of uninitialized value in concatenation (.) or string at ./compare +.pl line 25.
    Here is the updated code:
    #!/usr/bin/perl -w use Array::Compare; use strict; my $file1 = "/var/tmp/db.bind1"; my $file2 = "/var/tmp/db.bind2"; my $out = "/var/tmp/compare_out"; open(FILE1, "$file1") || die "Can't open $file1 to read\nReason: $!\n +"; my @file1 = <FILE1>; close(FILE1); open(FILE2, "$file2") || die "Can't open $file2 to read\nReason: $!\n +"; my @file2 = <FILE2>; close(FILE2); open(OUT, ">$out") || die "Cant create $out\nReason: $!\n"; my $comp = Array::Compare->new(DefFull => 1); print OUT "line $_ differs. File 1: $file1[ $_ ] != File 2: $file2[ $_ + ]\n" for $comp->full_compare(\@file1,\@file2); #$comp->compare(\@file1, \@file2); #print OUT $comp->full_compare(\@file1,\@file2); close(OUT); exit;

      That simply means that the value in one of the arrays is the null string ('') eg, a blank line.

      You can either trun of that particular warning with

      no warnings 'uninitialized';

      See perllexwarn for details.

      Or you could modify the print statement to provide better diagnostics.

      print OUT "line $_ differs. File 1: ", $file1[ $_ ] || '[blank]', " != File 2: ", $file2[ $_ ] || '[blank]', "\n" for $comp->full_compare(\@file1,\@file2);

      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
      If I understand your problem, I can solve it! Of course, the same can be said for you.

        Thanks for the help there that actually worked for me, but I think I am going to also give Merlyn's method a shot. Maybe the best solution is more simplistic, LOL. Thanks again, -Sunadmn

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-19 00:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found