F*******i 发帖数: 190 | 1 Can I ask perl to local the module dependent on the command line
argument inptu? such ash
./binperl --module=mod
in the binperl.pl
you can dynamiclly load the module mod and call a function
mod::function()?
Thanks! |
r****t 发帖数: 10904 | 2 probably you can, but I have no idea how... would
if ... require ...
simply work? |
F*******i 发帖数: 190 | 3 seems not to me.
【在 r****t 的大作中提到】 : probably you can, but I have no idea how... would : if ... require ... : simply work?
|
t****t 发帖数: 6806 | 4 perl -Mmodule binperl
on command line
or if you prefer to do it inside the program, "require" is actually a
function
【在 F*******i 的大作中提到】 : Can I ask perl to local the module dependent on the command line : argument inptu? such ash : ./binperl --module=mod : in the binperl.pl : you can dynamiclly load the module mod and call a function : mod::function()? : Thanks!
|
F*******i 发帖数: 190 | 5 Thank you very much for your hint.
Didn't figure out how to use require to achieve this goal.
Here is my problem:
./mybinary.pl --module=modA
or
./mybinary.pl --module=modB
I would like to use the symbol in modA or modB conditional on the argument
input.
such as in mybinary.pl:
I'd like:
if $module eq "modA"
require $module;
$module::function() does not work,
The other question is: is there any way to make a alias to $module,
that I can use
【在 t****t 的大作中提到】 : perl -Mmodule binperl : on command line : or if you prefer to do it inside the program, "require" is actually a : function
|
t****t 发帖数: 6806 | 6 I am not sure how to alias an entire module (I read through the document and
did some test, seems not work). But you can definitely alias a few
functions, such as:
require POSIX;
local *alias::floor = \&POSIX::floor;
alias::floor(0.5);
【在 F*******i 的大作中提到】 : Thank you very much for your hint. : Didn't figure out how to use require to achieve this goal. : Here is my problem: : ./mybinary.pl --module=modA : or : ./mybinary.pl --module=modB : I would like to use the symbol in modA or modB conditional on the argument : input. : such as in mybinary.pl: : I'd like:
|
S**********t 发帖数: 457 | |
F*******i 发帖数: 190 | 8 Thank you! It will be great if perl support alias for (package/modue).
and
【在 t****t 的大作中提到】 : I am not sure how to alias an entire module (I read through the document and : did some test, seems not work). But you can definitely alias a few : functions, such as: : require POSIX; : local *alias::floor = \&POSIX::floor; : alias::floor(0.5);
|
F*******i 发帖数: 190 | 9 Thank you,
will have a try.
【在 S**********t 的大作中提到】 : try UNIVERSAL::require
|