Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Oh enlightned ones,

I get the following error:

Can't locate object method "new" via package "Algorithm::Diff" at diff.pl line 25.
I am using Perl 5.8.4 on XP. My code is

require Algorithm::Diff; my $file_old = "file1.log"; my $file_new = "file2.log"; open ( F1, $file_old ) or die "Can't open $file_old : $!\n"; open ( F2, $file_new ) or die "Can't open $file_new : $!\n"; my @seq1 = <F1>; my @seq2 = <F2>; close ( F1 ); close ( F2 ); my $diff = Algorithm::Diff->new( \@seq1, \@seq2 ); $diff->Base( 1 ); # Return line numbers, not indices

I also tried changing it to 'use Algorithm::Diff'. What can be the cause of the error? Thanks in advance.

Replies are listed 'Best First'.
Re: Can't locate object
by Errto (Vicar) on Dec 08, 2004 at 01:50 UTC

    What version of Algorithm::Diff do you have installed? Try running the following to find out: perl -MAlgorithm::Diff -e'print $Algorithm::Diff::VERSION'. According to the docs, older versions did not support the object-oriented API. That could be the issue.

    Update: My theory was wrong.

    Update 2: I clearly don't know anything about ActivePerl. See below.

      Hello

      I have Algorithm::Diff version 1.1901. Is this an older version?

      Thank you.

        No, it is not. I guess my guess was wrong.

      No, your theory was correct. 1.1901 was the version installed with cygwin Perl which wasn't the Perl giving the error. PPM gets you version 1.15 which the original querent was eventually able to see was the problem (via the chatterbox).

      Since the original question mentions XP, it would have helped had you used Win32-style quoting in your suggestion of how to report the module version number:

      perl -MAlgorithm::Diff -e"print $Algorithm::Diff::VE­RSION"
      or, since Algorithm::Diff uses Exporter.pm, just:
      perl -MAlgorithm::Diff=9999 -e0

      (FYI)

      Thanks for the quick response with an excellent guess (which even turned out to be correct).

      - tye        

Re: Can't locate object
by Corion (Patriarch) on Dec 08, 2004 at 07:14 UTC

    This cannot be the actual code giving the error, because it doesn't have 25 lines. Please post the minimal script that produces the error, together with the actual error message as produced by this minimal script. For example, I could imagine that the following script produces the error message for you too:

    use strict; require Algorithm::Diff; my @seq1 = qw(1 2 3 4 6); my @seq2 = qw(1 2 4 5 6); my $diff = Algorithm::Diff->new( \@seq1, \@seq2 );

    Run this code, and report it back, together with the error message it produces. If this program works for you, your error must be somewhere else.