in reply to Re: Hash value test of zero
in thread Hash value test of zero
As the above code shows the "0 but true" exception is hard-coded into Perl as an exception. This allows a function to return a single value that can represent both logically true and numerically zero. Using that string as a numeric value will not cause a warning. This is now seldom seen as the exponential value 0E0 is more commonly used, especially by the DBI.
Interesting. From perlop:
Perl operators that return true or false generally return values that can be safely used as numbers. For example, the relational operators in this section and the equality operators in the next one return 1 for true and a special version of the defined empty string, "", which counts as a zero but is exempt from warnings about improper numeric conversions, just as "0 but true" is.
In my experience, this is well-known ... well much better known than the quirky dualvar ... which caused a sensation here recently when uncorked by marioroy during the long running Long List is Long saga. Mario is the only Perl programmer I know who has used dualvar in production code (in MCE::Shared::Cache part of MCE).
See also:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Hash value test of zero
by tobyink (Canon) on Jul 26, 2023 at 10:39 UTC | |
by eyepopslikeamosquito (Archbishop) on Jul 26, 2023 at 11:11 UTC | |
|
Re^3: Hash value test of zero
by NERDVANA (Priest) on Jul 27, 2023 at 05:14 UTC |