Answer the question
In order to leave comments, you need to log in
Why is '0' false in Perl (and '00' is not)?
The reason that prevented me from overcoming further difficulties in learning Perl arose at the very first acquaintance: bewilderment from the inconsistent, in my opinion, interpretation of the truth of strings ( ''
and '0'
- "false", the rest - "true").
On the one hand, it would be clear if any non-empty string was interpreted as true (as in AWK, JavaScript, Python, PowerShell ...), on the other hand, if any string with a numerical value of 0: '00'
, '0.0'
... was interpreted as false (as, for example, , in AutoHotkey).
Why is it done the way it's done? I doubt that for reasons of ease of execution, it would rather be easier to implement one of the two approaches I have indicated. Or, perhaps, there are some applied non-contrived cases in which just such a choice is justified? (Although, if we talk about the implementation of truth values, it’s also not entirely clear why “true” is a number 1
(although how to check that this is a number and not a string - how in Perl to find out the type of a scalar value?), but “false” - string ''
?)
(Yes, I know PHP is similar, but: it's done under the influence of Perl; PHP is a tool chosen not for love, but out of necessity; the level of entry into PHP is lower.)
I understand that such a question should first of all be asked to the creator of the language, but I think I am not the first to have such bewilderment and, perhaps, answers have already been given to it and, perhaps, even an admission of my own mistake ...
Additionally, much more general question: Is it worth learning Perl without much need? Does it have any aesthetic merits or areas of application that are primarily available to it? Regular expressions? But they are now available in most other languages either directly or through libraries (even if their syntax is borrowed from Perl).
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question