There are two things at work here. First, the false value of perl is actually neither strictly '' nor 0, it's kinda both (link to the doc when I find it). As demonstrated by

perl -E "use strict; use warnings; say( '' + 1 ); say( !1 + 1 ); say ! +1; say '!1 is defined' if defined !1" Argument "" isn't numeric in addition (+) at -e line 1. 1 1 !1 is defined
The warning about the non numeric argument happens only once, because !1 is treated as a number in arithmetic context. But printing !1 doesn't show anything because false is the empty string in string context.

~ however only works in two ways: bitwise not on a number, or bitwise not on a binary string. And the output will be of the same type. This means that ~~ is only equivalent to scalar when the operand is a number or a string, but it will force another type (probably string) on any other value (an object, a reference...).

Edit: one place where the special value of perl's false is mentioned: Relational Operators.
Also, ~~ is not equivalent to scalar for some big numbers and negative numbers:

DB<1> say ~~ (-1) 18446744073709551615
So it's better not to use it outside of obfuscated code.


In reply to Re: Inchworm vs scalar: on boolean false value by Eily
in thread Inchworm vs scalar: on boolean false value by rsFalse

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.