XP is just a number | |
PerlMonks |
Re: Secret Perl Operators: the boolean list squash operator, x!!by eyepopslikeamosquito (Archbishop) |
on Jul 31, 2006 at 21:40 UTC ( [id://564877]=note: print w/replies, xml ) | Need Help?? |
I remember this trick being employed in early golf games, though it was never given a name to the best of my knowledge. Searching the secret Terje/mtv pdf book of Perl Golf reveals five uses of this secret operator: 08-jun-2002: Piers Cawley, section 4.5, TPR(0,4) Interlinear Counts 19-jul-2002: Ton Hospel, section 3.11, Terje's Cryptoanalysis 17-jan-2003: Ton Hospel, section 5.20, LED Display 23-may-2003: Michal Jankowski, section 8.13, DEKODER 16-sep-2003: Mtv Europe, section 6.9, Huffman Codes
Update: It was also used by Ton Hospel and Mtv Europe in May 2003 to produce the shortest known Perl solution to 99 bottles of beer:
Notice that in golf, and different from Aristotle's example, the x!! secret operator is most commonly used in scalar context -- in the 99 bottles of beer example, it's used to generate either "s" or "", thus forming either "bottles" or "bottle". Sometimes golfers rely on the ! operator returning "" (and not 0) for false. AFAICT, this behaviour is not guaranteed anywhere in the official Perl docs, though it's mentioned in the Camel, in the "Ideographic Unary Operators" section, page 92: Unary ! performs logical negation, that is, "not". See not for a lower precedence version of logical negation. The value of a negated operand is true (1) if the operand is false (numeric 0, string "0", the null string, or undefined) and false ("") if the operand is true.
In Section
Meditations
|
|