Perl comparison operator output

I'm not quite sure what the result of the comparison is. For example, consider

$rr = 1>2; $qq = 2>1; print $rr; #nothing printed print $qq; #1 printed 

Is $rr an empty string? Is this documented somewhere? Or how can I say for sure?

I searched for the answer in Learning Perl from Schwartz et al, but could not immediately resolve the answer.

+5
source share
1 answer

http://perldoc.perl.org/perlop.html#Relational-Operators :

Perl statements that return true or false usually return values ​​that can be safely used as numbers. For example, the relational operators in this section and the equality operators in the following return 1 for true and a special version of the specified empty string, "which is considered to be zero, but freed from warnings about incorrect numerical conversions, just like" 0, but true. "

Thus, it returns what is an empty string in the context of the string, and 0 in the numeric context.

+4
source

Source: https://habr.com/ru/post/1271680/


All Articles