I'm posting this in Meditations instead of Seekers because it seems there is no such operator; I just read man perlop.

Anyhow, those familiar with logics might be familiar with "implication" operator: A -> B, from A follows B, or in more primitive terms: !A || (A && B). Used to say things like "if it rains, then it winds" - if it doesn't rain, the statement might as well be true but not applicable, if it does rain then we'll see if the statement is true by checking if it winds too.

My point? That perl should have one. It may sound like trivial operator ... but believe it or not, I actually encountered a case where it would have come in handy. I am writing this personal web proxy in perl that tampers with CGI requests. Now, multipart POST requests didn't go through because, in case of POST, I just fed the body to CGI.pm which interpreted it all wrong. Upon writing a check to only accept content-type: application/x-www-form-urlencoded, I ended up writing as following:

($method ne "post" || ($method eq "post" && $contenttype eq "application/x-www-form-urlencoded")

As you can clearly see, it would have been better written

($method eq "post") -> ($contenttype eq "application/x-www-form-urlencoded)

(of course, => operator is already in use. And so is ->.)

Still, with current operatorness, the way I wrote it is unsatisfactory. It duplicated terms ($method ne "post" vs. $method eq "post"), which is equivalent to code copying, which is Bad Thing. Right? I can think of some more ways to write this, but they all end up copying terms, so I suspect there really isn't way to make it neat with what there is.

So, maybe there should be implication-operator? And now that I think of it, why isn't there high-precence XOR operator (one corresponding to && and ||, "xor" is impractical with too low precedence)? Is it that they simply couldn't figure out proper characters for them?

...

OK, OK, I admit this might be a "bit" trivial issue but this really troubles me. And this is "Meditations" which apparently is cover name for "Ramblings", isn't it?

-Kaatunut


In reply to Implication operator by kaatunut

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.