加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

从命令行调用perl子例程

发布时间:2020-12-15 21:15:21 所属栏目:大数据 来源:网络整理
导读:好的,我想知道如何从命令行调用perl子例程.因此,如果我的程序被称为测试,并且子程序被称为字段,我想从命令行调用它. 测试领??域 解决方法 使用调度表. #!/usr/bin/perluse strict;use warnings;use 5.010;sub fields { say 'this is fields';}sub another {
好的,我想知道如何从命令行调用perl子例程.因此,如果我的程序被称为测试,并且子程序被称为字段,我想从命令行调用它.

测试领??域

解决方法

使用调度表.
#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

sub fields {
  say 'this is fields';
}

sub another {
  say 'this is another subroutine';
}

my %functions = (
  fields  => &;fields,another => &;another,);

my $function = shift;

if (exists $functions{$function}) {
  $functions{$function}->();
} else {
  die "There is no function called $function availablen";
}

一些例子:

$./dispatch_tab fields
this is fields
$./dispatch_tab another
this is another subroutine
$./dispatch_tab xxx
There is no function called xxx available

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读