转 perl 的调试

感谢toolic

We use Perl scripts to check if condition.

##code(t1) is as belows:



my @results=(93,4,0); my @param_array = ( [ "50", "<", "stat1", ], [ "1", "<", "stat2", ], [ "3", "<", "stat3", ], ); for ($i=0;$i<@results;$i++) { print (" ".$results[$i]." ".$param_array[$i][1]." ".$param_array[$i][0]." "); if ( $results[$i] + 0 < $param_array[i][0] + 0 ) { print " beend"; } else { print " end111"; } }

The result is strange. When 95<50, if condition is not true, and it prints end111. I think the statement is right.

But when 4 < 1, if condition is not true, it also prints beend. I think the the statement is wrong.

Why does this happen?

###result is as below
perl t1
   93 < 50 end111 4 < 1 beend 0 < 3 beend 

fix:

0

You should add use warnings; to your code, and you should see warning messages like:

Unquoted string "i" may clash with future reserved word
Argument "i" isn't numeric in array element

You need to change i to $i. Change:

if ( $results[$i] + 0 < $param_array[i][0] + 0 ) {

to:

if ( $results[$i] + 0 < $param_array[$i][0] + 0 ) {

This produces the following output, which I assume is what you want (although you didn't explicitly show your expected output:

 93 < 50 end111 4 < 1 beend 0 < 3 beend

猜你喜欢

转载自www.cnblogs.com/feiyun8616/p/12920038.html
今日推荐