Cool/useful short examples of Perl?
Paul Makepeace
paulm at paulm.com
Wed Jun 8 13:41:29 BST 2011
On Wed, Jun 8, 2011 at 13:17, Tom Hukins <tom at eborcom.com> wrote:
> On Wed, Jun 08, 2011 at 02:00:41PM +0200, Abigail wrote:
>> I'd rather go for sacking people that don't know the difference
>> between
>>
>> if (something) { ... }
>>
>> and
>>
>> unless (!something) { ... }
>
> It's sunny outside and pubs are open: I can think of worse times to
> lose my job.
>
>> Or does everyone think they are always equivalent?
>
> I'm not everyone, and with a language as flexible as Perl I hesitate
> to make strong statements involving words like "always", but I don't
> recall encountering a situation where they differ.
$ perl -le 'print "$_ == !!$_ ? ", $_ == !!$_ ? "yes" : "no" for (-1,
0, 1, 2, undef)'
-1 == !!-1 ? no
0 == !!0 ? yes
1 == !!1 ? yes
2 == !!2 ? no
== !! ? yes
FWIW,
$ python -c 'for x in -1, 0, 1, 2, None: nnx = not not x; print x,
"==", nnx, "?", "yes" if x == nnx else "no"'
-1 == True ? no
0 == False ? yes
1 == True ? yes
2 == True ? no
None == False ? no
(Wait, what? Command line python? Semicolons? Ternary ops?)
Paul
More information about the london.pm
mailing list