在 Perl 5 中,字符串和数字之间的区别何时重要? [英] When does the difference between a string and a number matter in Perl 5?
本文介绍了在 Perl 5 中,字符串和数字之间的区别何时重要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果 Perl 5 中的字符串通过 looks_like_number
,它也可能是一个数字.例如,
If a string in Perl 5 passes looks_like_number
, it might as well be a number. For instance,
my $s = "10" + 5;
导致 $s
被分配 15
.
在某些情况下,字符串的行为是否与其等价的数字不同?
Are there any cases where a string does not behave like its numeric equivalent would?
推荐答案
处理按位运算符时.123 ^ 456
是 435,但 "123" ^ "456"
是 "\x05\x07\x05"
.如果任一操作数是数字,则按位运算符以数字方式工作.
When dealing with bitwise operators. 123 ^ 456
is 435, but "123" ^ "456"
is "\x05\x07\x05"
. The bitwise operators work numerically if either operand is a number.
这篇关于在 Perl 5 中,字符串和数字之间的区别何时重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文