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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Implication operator
by chipmunk (Parson) on Dec 11, 2000 at 03:54 UTC | |
|
Re (tilly) 1: Implication operator
by tilly (Archbishop) on Dec 11, 2000 at 05:19 UTC | |
|
Re: Implication operator
by Fastolfe (Vicar) on Dec 11, 2000 at 07:38 UTC | |
|
Re: Implication operator
by clemburg (Curate) on Dec 11, 2000 at 15:29 UTC | |
by kaatunut (Scribe) on Dec 11, 2000 at 21:15 UTC | |
by chipmunk (Parson) on Dec 11, 2000 at 21:38 UTC | |
by Fastolfe (Vicar) on Dec 11, 2000 at 21:26 UTC | |
by chipmunk (Parson) on Dec 11, 2000 at 21:52 UTC | |
by Fastolfe (Vicar) on Dec 11, 2000 at 23:56 UTC | |
|
Re: Implication operator
by mrmick (Curate) on Dec 11, 2000 at 20:14 UTC |