Undefined subroutine &PDL::divide

undefined subroutine &main
undefined subroutine &main encode
undefined subroutine &main move called at
undefined subroutine &main encode_json
undefined subroutine &main decode called at
undefined subroutine &main::trim called at
undefined subroutine &main ceil
flyloader undefined subroutine

I'm trying Perl's PDL in the following code:

#!/usr/bin/perl  -w
use strict;
use PDL::Core qw(pdl);
use PDL::Math qw(isfinite);
use PDL::Primitive qw(statsover);


my $div = 4;
my @array1 = (0..10);
my $pdl_array = log(pdl(@array1)/$div);
$pdl_array->where(!isfinite($pdl_array)) .= 0;
my($mean,$stdev) = statsover($pdl_array);
die $pdl_array,"\n",$mean," ",$stdev,"\n";

and I'm getting this error:

Undefined subroutine &PDL::divide called at ./compare_const.pl line 10.

Any hint, please?Thanks a lot.

PDL is unusual in its design, and therefore has an unusual and somewhat fragile import mechanism. Each PDL module adds functionality to PDL by inserting a new method directly into PDL's package. This decision was made very early in the design of PDL v2, and has not been changed in the intervening decade. (There's no reason it couldn't be changed, even in a backward compatible way, but none of the PDL developers have set aside the time to do so.)

As a result, you must load a handful of modules to ensure that PDL has its requisite, basic functionality. If you take a look at PDL's import function, you'll notice that it explicitly loads a number of packages into the caller's namespace. The reason for this is good---splitting functionality across multiple modules to keep the distribution sane---but the implementation is not aligned with common Perl practices. This is why your attempt to import specific functions into your namespace failed.

The solution has already been explained. Either replace all of your use PDL::... statements with a single use PDL:

use strict;
use warnings;
use PDL;

my $div = 4;
...

or say use PDL::Lite (to ensure that PDL's package is complete) and then import the specific functions into your (main) package

use strict;
use warnings;

use PDL::Lite;
use PDL::Core qw(pdl);
use PDL::Math qw(isfinite);
use PDL::Primitive qw(statsover);

my $div = 4;
...

In Perl, why do I get "undefined subroutine" in a perl module but not , You imported capture_exec_combined by the use clause before declaring the package, so it was imported into the main package, not the� At 12:41 AM +0800 3/8/12, lina wrote: >Hi, > >$ ./substr_accessing_examples.pl >Undefined subroutine &main::subst called at >./substr_accessing_examples.pl line 15.

Just add use PDL; and your code will work:

#!/usr/bin/perl  -w
use strict;

use PDL;
use PDL::Core qw(pdl);
use PDL::Math qw(isfinite);
use PDL::Primitive qw(statsover);

my $div = 4;
my @array1 = (0..10);
my $pdl_array = log( pdl(@array1) / $div );
$pdl_array->where(!isfinite($pdl_array)) .= 0;
my ($mean, $stdev) = statsover($pdl_array);
die $pdl_array, "\n", $mean, " ", $stdev, "\n";

Outputs:

[0 -1.3862944 -0.69314718 -0.28768207 0 0.22314355 0.40546511 0.55961579 0.69314718 0.81093022 0.91629073]
0.112860814716055 0.696414187766251

Undefined subroutine, This is what I get About to use Module Undefined subroutine &main::Prt called at C:\dev\Source_Perl\MiscTests +\mod.pl line 8. [download]. I tried changing� you passed: this is an arg. func2: im called by, main::test_package.pl at 7 res = 30 --- b = Undefined subroutine &B::fib called at test_package.pl line 11. I dont understand, why im not able to call a function which is defined in the module or Why does Perl says 'Undefined subroutine'. thanks, katharnakh.

PDL has a minimum set of things that must be loaded. To get these all properly loaded, you must either use PDL (which also exports a bunch of stuff) or use PDL::Lite.

(I for some reason thought you were explicitly calling PDL::divide directly and getting that error, hence my original answer below.)

Original answer:

I'm wondering why you think that should work?

Yes, PDL exports a bunch of stuff (if you use it, which you do not), but that doesn't give you any guarantee about where it is exporting it from. (In point of fact, it appears to export from a number of different places directly into the use`ing package.)

If you are trying to avoid namespace pollution, I would recommend either importing into a designated package and using stuff from there:

{
    package My::PDL;
    use PDL;
}
...
My::PDL::divide...

or using the OO interface (see PDL::Lite, I think?)

Undefined subroutine &main::func1 [SOLVED], module after the modification on the module file but the error remains the same . Undefined subroutine &main::func1 called at client.pl line 9. You've got "promt" not "prompt" which is a subroutine that is undefined. You should really also add use strict; to your code, and then rejig it - it'll generate a lot more errors initially, but it'll avoid some real gotchas in future if you spell a variable incorrectly.

Modules and Packages, Let's construct a few subroutines to determine basic statistics. These will use a Undefined subroutine &main::average called at stats.pl line 7. To fix this, you� That module changed the name of the startform function to start_form in 2009, and removed the old name completely with version 4.04 in 2014. Our servers started using this newer version in 2018. The author of the script you use has probably released a new version that fixes the function name and works properly.

perl, hmmmnot sure what the problem is, your code works fine for me. Are you sure the B.pm file you posted is the file your main script is� Perl - undefined subroutine. Ask Question Asked 6 years, There is no sendmail subroutine in that program. Instead, if you look at the header, you'll see:

"Undefined subroutine" error (but it's defined, I think?), Re: "Undefined subroutine" error (but it's defined, I think?) Bob Walton ( bwaltonrochester.rr.com) wrote on MMMDC September MCMXCIII in <URL:news: � Comment on Undefined subroutine &main error; Select or Download Code; Replies are listed 'Best First'. Re: Undefined subroutine &main error

Comments
  • Try using the default use PDL::Core; without any explicit import list.
  • @toolic same thing; anyway it is calling it with package prefix.
  • that indeed worked. Thanks! But any reason why the compiler assigns the division operation to PDL?
  • Thenks @ysth. Got any idea why is divide supposedly located in PDL?
  • it isn't, and I don't see any documentation that says it is.
  • ah, I misunderstood the original question; editing my answer.
  • ysth, minor typo: you say PDF::divide. I tried to fix your typo with an edit, but stackoverflow wouldn't let me.