[OT] Perl woes

Jonathan Stowe jns at integration-house.com
Wed Jan 28 12:26:24 GMT 2009


2009/1/28 Mark Blackman <mark at blackmans.org>:
>
> On 28 Jan 2009, at 12:01, Paul Makepeace wrote:
>
>> On Wed, Jan 28, 2009 at 11:31 AM, Dominic Thoreau
>> <dominic.thoreau at googlemail.com> wrote:
>>>
>>> 2009/1/28 Jonathan Kimmitt <Jonathan.Kimmitt at csr.com>:
>>>>
>>>>      The next time I use == instead of eq to compare two strings, I
>>>> will know to expect it will always
>>>>      evaluate to true.
>>
>> Interesting that everyone's said to "use warnings" but no-one's
>> questioned what you're saying. Perl appears to me to DTRT:
>>
>> $ perl -le 'print "yes" if "a" == "2"'
>> $ perl -le 'print "yes" if "a" == "a"'
>> yes
>> $ perl -le 'print "yes" if "1" == "1"'
>> yes
>> $ perl -le 'print "yes" if "1" == "0"'
>> $ perl -le 'print "yes" if "1" == 1'
>> yes
>> $
>>
>> Can you give an example where perl is doing something surprising to you?
>
> perl -le 'print "yes" if "a" == "b"'
>
> Is the kind of case I suspect he's hit.


I guess that "non-number used in a numeric or arithmetic context is
treated as 0" isn't at all obvious to the beginner.  We tend to think
that DWIM is one of the strengths of Perl, but someone not coming from
a Perl background is likely to have a totally different value of
"WIM" than that catered for by Perl :-)

/J\
-- 
http://rabidgravy.com/ - Music
http://gellyfish.co.uk/ - Everything else


More information about the london.pm mailing list