Why does perl treat the string "0" as false? -


this question has answer here:

i found in text string '0' equivalent 0, hence condition false in perl.

but when looked @ ascii table '0' ascii 48. why perl consider string '0' value 0 in control structure ?

if ('0'){         print "statement1 \n";         }  else {         print "statement2\n";       } 

because specified so.

the number 0, strings '0' , '', empty list "()", , "undef" false in boolean context. other values true. negation of true value "!" or "not" returns special false value. when evaluated string treated '', number, treated 0.

that's specification. behavior conforms.


as why specification written -- perl makes practice of implicitly converting between strings , numbers, , in respect not use ascii value decimal value. treating '0' in same manner 0 in context consistent behavior of allowing '9'+1 return 10, rather ':' (the next ascii value).


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -