Cool/useful short examples of Perl?

Roger Burton West roger at firedrake.org
Wed Jun 8 13:56:13 BST 2011


On Wed, Jun 08, 2011 at 01:41:29PM +0100, Paul Makepeace wrote:

>$ perl -le 'print "$_ == !!$_ ? ", $_ == !!$_ ? "yes" : "no" for (-1,
>0, 1, 2, undef)'
>-1 == !!-1 ? no
>0 == !!0 ? yes
>1 == !!1 ? yes
>2 == !!2 ? no
> == !! ? yes

Might as well add lua, since I'm trying to learn it at the moment (and
therefore this is unlikely to be idiomatic). Having explicit boolean
types makes it all a bit more predictable, I feel.

$ lua -e 'function process(x) y=not not x;print(x,"==",y,"?",(y==x)) end for x=-1,2 do process(x) end process(nil) process(true) process(false)'
-1	==	true	?	false
0	==	true	?	false
1	==	true	?	false
2	==	true	?	false
nil	==	false	?	false
true	==	true	?	true
false	==	false	?	true

Roger


More information about the london.pm mailing list