in reply to Why is this evaluating to true?

pmarcoen:

The statement isn't necessarily wrong--perl does automatic conversions between numbers and strings, and strings that don't "look like a number" get converted to 0 when you treat them like a number. After all, in a data stream, there may be multiple different data types that you would want to handle differently without lots of explicit type conversions and such. (If you're a fan of explicit conversions, perhaps you should be a Java programmer? </joke>)

Here's a simple (useless!) example of treating different types of data differently:

$ cat 938362.pl #!/usr/bin/perl use strict; use warnings; use Scalar::Util qw(looks_like_number); my $t; while ($t = <DATA>) { $t=~s/\s+$//; print "\ninput = '$t'\n"; if (looks_like_number($t)) { print "looks numeric\n"; if ($t == 0) { print "Gotta have somethin' if ya wanna be with me\n"; } else { print "There are $t ways to leave your lover\n"; } } else { print "non-numeric\n"; if ($t eq "Godzilla") { print "Oh, no! There goes Tokyo, go go $t!\n"; } elsif ($t =~ /horse/i) { print "A horse is a horse of course, of course\n"; } else { print "insert song lyric here...\n"; } } } __DATA__ Godzilla 50 A horse of a different color 0 zebra $ perl 938362.pl input = 'Godzilla' non-numeric Oh, no! There goes Tokyo, go go Godzilla! input = '50' looks numeric There are 50 ways to leave your lover input = 'A horse of a different color' non-numeric A horse is a horse of course, of course input = '0' looks numeric Gotta have somethin' if ya wanna be with me input = 'zebra' non-numeric insert song lyric here...

Since using text strings where numbers are expected is a common logic error, the warnings package tells you when you try to convert a string that doesn't look like a number into a number.

...roboticus

When your only tool is a hammer, all problems look like your thumb.