我有这个简短的Perl脚本:
[red@tools-dev1 ~]$cat so.pl#!/usr/local/bin/perl -wuse strict;while(<DATA>) { chomp; my ($arg1,$arg2,$op ) = split /,/; if ( $op eq '=' ) { $op = 'eq'; } my $cmd = "$arg1 $op $arg2"; print "[$cmd]\n"; my $rc = eval $cmd || 0; print "rc is [$rc]\n";}__DATA__cat,cat,=
当我执行它时,我得到:
[red@tools-dev1 ~]$./so.pl[cat eq cat]rc is [0]
有人会认为你会……
[cat eq cat]rc is [1]
…因为“猫”等于“猫”,对吧?
解决方法 您在严格模式下使用裸字,这是一个错误:$perl -e 'use strict; cat eq cat'bareword "cat" not allowed while "strict subs" in use at -e line 1.bareword "cat" not allowed while "strict subs" in use at -e line 1.Execution of -e aborted due to compilation errors.
每当你评估一个字符串时,你应该检查$@以查看是否有错误.
总结以上是内存溢出为你收集整理的我的eval是错误的还是我不理解Perl中的eq vs ==全部内容,希望文章能够帮你解决我的eval是错误的还是我不理解Perl中的eq vs ==所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)