由于我完成了任何Perl工作并需要编写一个信用卡处理模块,这已经有一段时间了。该模块将有几个子例程,但一旦我找出如何做一个,我可以做其余的。第一个子程序是添加客户信息。我需要的信息是客户号码,名字,姓氏,地址,城市,州和邮编。所有这些信息将由调用程序提供,但一些字段可能为空。Perl如何将数据传递到模块中的子例程
sub addCustomer()
{
my $tx = new Business::OnlinePayment("USAePay");
$tx->content(
login => LOGIN,
password => PASSWORD,
type => "CC",
action => 'Recurring Authorization',
description => 'Business::OnlinePayment test',
amount => '49.95',
invoice_number => '100100',
name => 'Tofu Beast',
card_number => '46464646464646',
expiration => '11/08',
address => '1234 Bean Curd Lane, San Francisco',
zip => '94102',
);
$tx->submit();
if($tx->is_success()) {
print "Card processed successfully: ".$tx->authorization."\n";
} else {
print "Card was rejected: ".$tx->error_message."\n";
}
}
你应该通过阅读和吸收[Perl的子程序(http://perldoc.perl.org/perlsub.html)和 [Perl模块,风格指南](http://perldoc.perl.org启动/perlmodstyle.html) – Borodin
[Perl Subroutine Arguments]的可能重复(http://stackoverflow.com/questions/19234209/perl-subroutine-arguments) –
请勿使用原型(sub-declaration中的圆括号)。他们不是必需的,他们不会做你认为他们做的事。他们会更可能给你奇怪的错误比其他任何事情。它们被用来使子程序模仿内置函数,没有别的。你的应该是'sub addCustomer {'。 – TLP