你如何创建一个Perl模块?
发布时间:2020-12-15 21:30:39 所属栏目:大数据 来源:网络整理
导读:你如何为Perl编写一个模块?在 Python中,您可以使用: # module.pydef helloworld(name): print "Hello,%s" % name# main.pyimport modulemodule.helloworld("Jim") 解决方法 一类: # lib/Class.pmpackage Class;use Moose;# define the class1; 导出功能的
你如何为Perl编写一个模块?在
Python中,您可以使用:
# module.py def helloworld(name): print "Hello,%s" % name # main.py import module module.helloworld("Jim") 解决方法
一类:
# lib/Class.pm package Class; use Moose; # define the class 1; 导出功能的模块: # lib/A/Module.pm package A::Module; use strict; use warnings; use Sub::Exporter -setup => { exports => [ qw/foo bar/ ],}; sub foo { ... } sub bar { ... } 1; 使用这些脚本: # bin/script.pl #!/usr/bin/env perl use strict; use warnings; use FindBin qw($Bin); use lib "$Bin/../lib"; use Class; use A::Module qw(foo bar); print Class->new; print foo(),bar(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |