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

I downloaded the Diff pm and am running the standard diff.pl script which looks like this
#!/usr/bin/perl # # `Diff' program in Perl # Copyright 1998 M-J. Dominus. (mjd-perl-diff@plover.com) # # This program is free software; you can redistribute it and/or modify + it # under the same terms as Perl itself. # use Diff qw(diff); bag("Usage: $0 oldfile newfile") unless @ARGV == 2; my ($file1, $file2) = @ARGV; #my $file1 = shift; #my $file2 = shift; # -f $file1 or bag("$file1: not a regular file"); # -f $file2 or bag("$file2: not a regular file"); -T $file1 or bag("$file1: binary"); -T $file2 or bag("$file2: binary"); open (F1, $file1) or bag("Couldn't open $file1: $!"); open (F2, $file2) or bag("Couldn't open $file2: $!"); chomp(@f1 = <F1>); close F1; chomp(@f2 = <F2>); close F2; $diffs = diff(\@f1, \@f2); exit 0 unless @$diffs; foreach $chunk (@$diffs) { foreach $line (@$chunk) { my ($sign, $lineno, $text) = @$line; printf "%4d$sign %s\n", $lineno+1, $text; } print "--------\n"; } exit 1; sub bag { my $msg = shift; $msg .= "\n"; warn $msg; exit 2; }

but I am getting this error, can someone interpret (ie how to remedy) it for me ?
Undefined subroutine &main::diff called at diff.pl line 32.
which is the
$diffs = diff(\@f1, \@f2);
line
Thanks

Replies are listed 'Best First'.
Re: diff.pl error
by ikegami (Patriarch) on Dec 14, 2005 at 23:53 UTC

    I believe the anonymous monk has led you down the wrong path. If Perl wasn't able to find Diff.pm, it would have given you a different error ("Can't locate Diff.pm in @INC").

    The problem is that Diff does not export diff. The problem is in Diff, or the problem is in your usage of Diff. We'd have to see Diff to help you more.

    Quick Tip #1

    Diff.pm should contains something like

    @EXPORT_OK = qw( diff ); @ISA = qw( Exporter ); require Exporter;

    Quick Tip #2

    Make sure to use use Diff ... if Diff.pm contains package Diff;, or
    make sure to use use diff ... if diff.pm contains package diff;.
    In Windows, using the wrong case in the use statement will load the module, but will prevent importing from working.

Re: diff.pl error
by Anonymous Monk on Dec 14, 2005 at 22:36 UTC
    the 'diff' subroutine is in the file diff.pm. This module has to be in one of your include directories. Try this:
    perl -d diff.pl file1 file2 ... DB<1> x @INC 0 'C:/Perl/lib' 1 'C:/Perl/site/lib' 2 '.' DB<2>q
    This will show you what your include directories are. diff.pm has to be in one of them.

    Oryx3