本文介绍了避免“数字式(==)中不是数字"警告的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#!/usr/bin/env perl
use warnings;
use 5.12.2;

my $c = 'f'; # could be a number too

if ( $c eq 'd' || $c == 9 ) {
    say "Hello, world!";
}

最好的方法是避免在./perl.pl第7行的数字eq(==)中参数"f"不是数字"?-警告?我想在这种情况下我可以使用两次"eq",但这看起来并不好.

What is the best way, to avoid the 'Argument "f" isn't numeric in numeric eq (==) at ./perl.pl line 7.'-warning?
I suppose in this case I could use "eq" two times, but that doesn't look good.

推荐答案

不确定为什么要避免该警告.警告告诉您程序中存在潜在问题.

Not sure why you want to avoid the warning. The warning is telling you that there's a potential problem in your program.

如果要将数字与包含未知数据的字符串进行比较,则要么必须使用"eq"进行比较,要么以某种方式清理数据以使它看起来像像数字一样.

If you're going to compare a number with a string that contains unknown data, then you're either going to have to use 'eq' for the comparison or clean up the data in some way so that you know it looks like a number.

这篇关于避免“数字式(==)中不是数字"警告的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 07:32