【发布时间】:2020-12-06 11:27:48
【问题描述】:
我正在使用 Perl 脚本的不同子例程。 可以通过 Unix shell 从 Perl 脚本调用单个子例程,例如:
简化示例:
perl automated_mailing.pl inf
然后调用来自automated_mailing.pl 的函数inform_user。
这是通过调度表实现的:
my %functions = (
inf=> \&inform_user,
);
inform_user 看起来像
sub inform_user{
print "inform user: Angelo";
...some other stuff...
}
现在的问题是,如何用变量替换“Angelo”并从 shell 中调用它,例如:
sub inform_user{
my ($to)=@_;
print "inform user: $to";
}
这个调用不起作用:
perl automated_mailing.pl inf("Brian")
如何正确完成?
【问题讨论】:
标签: perl unix command-line