仅从 perl PDL 导出 pdl()
我只想从 PDL
导出 pdl()
函数,以避免与其他自动导出的函数(例如 max
、median)发生命名空间冲突
、sum
、intersect
等。但是,当我尝试时
use PDL qw(pdl);
它不起作用,因为上述函数仍然被导出(并且我收到有关重新定义函数的警告)。
另一方面,如果我这样做,
use PDL qw();
碰撞就不会发生。但是,当我尝试通过 PDL::pdl()
在程序中使用 pdl()
函数时,它失败并显示以下错误消息:
Can't call method "new" on unblessed reference at Basic/Core/Core.pm.PL (i.e. PDL::Core.pm) line 934.
另外,我在脚本内尝试过
{
require PDL;
pdl();
}
我收到同样的错误消息。
有人可以建议我如何仅导出 pdl() 吗?谢谢!
I want to export only the pdl()
function from PDL
to avoid namespace collision with other automatically exported functions such as max
, median
, sum
, intersect
etc. However, when I tried
use PDL qw(pdl);
it doesn't work as the aforementioned functions still get exported (and I get warnings on functions being redefined).
On the other hand, if I do
use PDL qw();
The collision doesn't happen. But when I try to use the pdl()
function in the program via PDL::pdl()
, it fails with this error message:
Can't call method "new" on unblessed reference at Basic/Core/Core.pm.PL (i.e. PDL::Core.pm) line 934.
Also, I tried inside the script
{
require PDL;
pdl();
}
I get the same error message.
Can someone advice on how I can export pdl() only? Thx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,我有点惊讶
use PDL qw()
的作用与use PDL
不同。事实上,我不明白它是如何做到的:来自PDL::import
的代码不关注它的参数。为此目的创建了一个名为PDL::Lite
的不同模块,它相当于:删除了通常
使用 PDL
中的一些额外内容,并且没有函数被导入。 (PDL::Lvalue
和PDL::Version
不会导出任何内容。)关于第二个问题,当您
使用 PDL::Lite
时,您仍然可以使用PDL->pdl(1, 2, 3)
获取pdl
构造函数。您不能说PDL::pdl(1, 2, 3)
因为构造函数实际上是在PDL::Core
包中定义的。去算算吧。因此,PDL::Core::pdl(1, 2, 3)
符合您的意思,但不是显而易见的选择。I'm actually a bit surprised that
use PDL qw()
does anything different fromuse PDL
. In fact, I don't see how it can: the code fromPDL::import
doesn't pay attention to its arguments. A different module was created for this very purpose calledPDL::Lite
, which is equivalent to:Some of the extras from the usual
use PDL
are cut out, and none of the functions are imported. (PDL::Lvalue
andPDL::Version
do not export anything.)On to your second question, when you
use PDL::Lite
, you can still get at thepdl
constructor withPDL->pdl(1, 2, 3)
. You cannot sayPDL::pdl(1, 2, 3)
because the constructor is actually defined in thePDL::Core
package. Go figure. So,PDL::Core::pdl(1, 2, 3)
does what you meant, but is not the obvious choice.我想如果你只导入 PDL::Core,你只会得到这个模块中的函数。
I guess if you only import PDL::Core, you'll get only the functions in this module.