Since quite a while i am having pain with a module import issue.
Here i post 2 examples from which the first does not work.
It would be very nice if one could explain, why my first example
does not work. What do i need to do getting it working?
Thx a lot! Axel
1. example, 1xScript, 2xModul
Result:
(16:14:59) [2] ./test.pl
main company::show_company
Undefined subroutine &company::read_artist called at company.pm line
33 (#1)
(F) The subroutine indicated hasn't been defined, or if it was, it
has
since been undefined.
Uncaught exception from user code:
Undefined subroutine &company::read_artist called at
company.pm line 33.
at company.pm line 33
company::show_company() called at ./test.pl line 15
test.pl
##################
#!/usr/bin/perl
use warnings;
use diagnostics;
use strict;
use artist qw {
show_artist
};
use company qw {
show_company
};
show_company();
show_artist();
artist.pm
########################
package artist;
use warnings;
use diagnostics;
use strict;
use company qw {
read_company
};
use Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(
read_artist
show_artist
);
sub read_artist {
my ( $package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask ) =
caller( 0 );
print STDOUT "$package $subroutine\n";
}
sub show_artist {
my ( $package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask ) =
caller( 0 );
print STDOUT "$package $subroutine\n";
read_company();
read_artist();
print "Show Artist and the appendant Company...";
}
return(1);
company.pm
######################
package company;
use warnings;
use diagnostics;
use strict;
use artist qw {
read_artist
};
use Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(
read_company
show_company
);
sub read_company {
my ( $package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask ) =
caller( 0 );
print STDOUT "$package $subroutine\n";
}
sub show_company {
my ( $package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask ) =
caller( 0 );
print STDOUT "$package $subroutine\n";
read_artist();
read_company();
print "Show Company and the appendant artists...";
}
return(1);
##############################################################
2. example, 1xScript, 4xModul
Result:
(17:22:51) [3] ./test.pl
main company::show_company
company artist_read::read_artist
company company_read::read_company
Show Company and the appendant artists...
main artist::show_artist
artist company_read::read_company
artist artist_read::read_artist
Show Artist and the appendant Company...
test.pl
##################
#!/usr/bin/perl
use warnings;
use diagnostics;
use strict;
use artist qw {
show_artist
};
use company qw {
show_company
};
show_company();
show_artist();
artist.pm
########################
package artist;
use warnings;
use diagnostics;
use strict;
use company_read qw {
read_company
};
use artist_read qw {
read_artist
};
use Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(
show_artist
);
sub show_artist {
my ( $package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask ) =
caller( 0 );
print STDOUT "$package $subroutine\n";
read_company();
read_artist();
print "Show Artist and the appendant Company...\n";
}
return(1);
company.pm
######################
package company;
use warnings;
use diagnostics;
use strict;
use artist_read qw {
read_artist
};
use company_read qw {
read_company
};
use Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(
show_company
);
sub show_company {
my ( $package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask ) =
caller( 0 );
print STDOUT "$package $subroutine\n";
read_artist();
read_company();
print "Show Company and the appendant artists...\n";
}
return(1);
artist_read.pm
######################
package artist_read;
use warnings;
use diagnostics;
use strict;
use Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(
read_artist
);
sub read_artist {
my ( $package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask ) =
caller( 0 );
print STDOUT "$package $subroutine\n";
}
return(1);
company_read.pm
######################
package company_read;
use warnings;
use diagnostics;
use strict;
use Exporter;
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT_OK = qw(
read_company
);
sub read_company {
my ( $package, $filename, $line, $subroutine, $hasargs,
$wantarray, $evaltext, $is_require, $hints, $bitmask ) =
caller( 0 );
print STDOUT "$package $subroutine\n";
}
return(1);
You have mutually recursive modules. (That is A uses B which uses A). Perl can run into
problems in situations like this. Best advice is to refactor your code so you don't have
a loop like this.