Once you've done the
eval "require $class";
part, you just need
$class->mysub();
to call it. Here's a working example.
Module './pm_1175392/mymod123.pm':
package pm_1175392::mymod123; sub mysub { return 'In package: ' . __PACKAGE__; } 1;
Script './pm_1175392_variable_name_mod.pl':
#!/usr/bin/env perl -l use strict; use warnings; my $modno = '123'; my $class = "pm_1175392::mymod$modno"; eval "require $class"; print $class->mysub();
Sample run:
$ ./pm_1175392_variable_name_mod.pl In package: pm_1175392::mymod123 $
The require documentation has information on the eval part. See "perlobj: Invoking Class Methods" for information on the calling part.
Regarding the bit now "under the carpet", please don't do that. It's better to <strike> such text so that subsequent posts still make sense (all explained here). And, yes, I am "just across the ditch" :-)
— Ken
In reply to Re^3: Call sub in variable module
by kcott
in thread Call sub in variable module
by tel2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |