聘我网

新概念招聘3.0

命令行运行Perl报错

vote up0vote downstar
[root@ test]$ perl -e "%hash=(key,1);print 2 if exists $hash{key};"
exists argument is not a HASH or ARRAY element at -e line 1.

这段程序放到单独的文件中执行不会报错,命令行就不行,为何?

 

1 个答复

vote up0vote downcheck

$hashshell变量内插了,需要用\进行转义:

perl -e "%hash=(key,1);print 1 if exists \$hash{key};"

或者使用单引号:

perl -e '%hash=(key,1);print 1 if exists $hash{key};'
链接

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.