http://qs321.pair.com?node_id=11105250

Recently, jdporter closed one of his comments with the following snippet: $orry - not $orry

This is a valid Perl expression. So, I wondered, what is its value? My first thought was "easy: that's just $orry converted to a number", but as ever so often, my first thought is wrong. If $orry = 0, then the value is -1. If $orry is a string, then the value is 0. Unless the string is empty, in which case the value is -1. And unless the string starts with a number, where the result is that number, even if the number is 0. And then, there are references, typeglobs, tied scalars, and objects, which may even overload stuff.

Here's a collection of expressions for $orry, and results of $orry - not $orry.

$orry : $orry - not $orry 42 : 42 -1 : -1 0 : -1 undef : -1 "" : -1 0e0 : -1 "0e0" : 0 "a123" : 0 "-.2e2e" : -20 "nancy boy" : NaN "infidelity" : Inf *STDOUT : 0 [] : 94269931603432 File::Temp->new : 94269935380840 URI->new(q(https://perl.org/)) : 0

The implicit conversions of scalars into numeric / boolean / string context are amazing, and sometimes scary. Fortunately, use warnings; detects most of the surprising ones.

Update:: syphilis contributed the strings "nancy boy" and "infidelity" which are indeed amusing additions. I inserted them after the strings starting with numbers. In the case of 'nancy boy' my text "string starts with a number" looks silly because NaN claims to be not a number.