Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Does not seem to me that you have read and understood my previous post carefully. What you said is right, but it does not mean anything here.

I was only adding a bit of information on the subject. That is quite a rant you responded with. Perhaps you should take a step back.

To be very clear, let's start back at the beginning. You said:

in scalar context, m// returns either 1 or 0.
to which AnonyMonk replied:
<pedantic> actually, m// in scalar context returns either 1 or "" (empty string). </pedantic>.
And to be extra clear, I'll be blunt: Y'all are both wrong (and y'all are both right). When m// fails in a scalar context, it returns 'the false value'. That is, it returns the standard value that the perl interpreter itself uses all over the place when 'false (but defined)' is to be returned. It is prepopulated with both a string value ("") and a numeric value (0 -- actually both the IV 0 and the NV 0.0 according to the dumps provided by AnonyMonk).

In C code, this value has a short name, PL_sv_no. When talking Perl, it also deserves a short name. A very short and useful name for it is !1 (useful because you can actually use it in your Perl code when you want a really good 'false' value).

You failed to answer why should "~" receive 0, when "~" can be applied against "empty string" with no problem, and as we see thru lots of my demo, m// actually returns "empty string" from time to time to represent "false".

Yes, I didn't say anything about that. I guessed that you already knew why.

I asked how much 1+1 is, and you answered 2+3=5.

I didn't see you ask anything. Next time you want to know something, you might want to actually ask the question (or read the docs). I thought you were just pounding a point about how the value that m// returns on failure has '0 nature' at least as much as it has '"" nature'.

for "~", although it can be used against both string and number, when both "" and 0 are available to be used, Perl arbitrarily picks 0.

Well, it isn't particularly arbitrary. The bit-wise operators prefer to work on numbers because that is the most expected behavior (this is what they do in C, from which they were borrowed). They prefer numbers to the point that if either operand has ever been used in a numeric context, then numeric results will be returned. This is important because most of the ways Perl code extracts a number from some external source will actually first give you a string (which automatically gets its numeric value when you try to use it as a number).

To get string values from bit-wise operators, all the operands must have only string values. And this is documented in the docs I link to above.

And on a personal note, next time you feel that you "asked how much 1+1 is" and someone "answered 2+3=5", you might want to think about why someone might have done such a thing. Although sometimes the answer is that "the answerer is an idiot and a rant would be a good reply", I suppose.

                - tye

In reply to Re^6: m//g behaves strange... (!1!) by tye
in thread m//g behaves strange... by Anonymous Monk

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    NodeReaper shuffles a deck of punched cards

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (4)
    As of 2018-05-21 15:46 GMT
    Find Nodes?
      Voting Booth?