小编per*_*ion的帖子

如何在perl中使用hash和getopts

我必须GetOptions在哈希数组中使用.

我的要求是编写一个包含多个选项组合的Perl脚本,例如:

test.pl -a mango -s ripe -d <date value>
Run Code Online (Sandbox Code Playgroud)

要么

 test.pl -a apple -s sour 
Run Code Online (Sandbox Code Playgroud)

其中mango,ripe,apple,sour,等是用户输入,其还用于存储在可变绑定SQL在WHERE一个条款SELECT查询来生成报告.

我这个代码

use vars qw ($opt_a $opt_s $opt_d)
Getopts('a:s:d:')
Run Code Online (Sandbox Code Playgroud)

现在我在编写hash方面遇到了一个问题

my %hash = @ARGV 
Run Code Online (Sandbox Code Playgroud)

上面的哈希定义是正确的吗?有没有更好的方法来使用哈希?

perl

0
推荐指数
1
解决办法
260
查看次数

标签 统计

perl ×1