in reply to perl typecasting
Something that will help you is to use strictures (use strict; use warnings;). They pick up errors and questionable code early.
In the case of Perl being shown a non-integer string in a context where a number is expected use warnings; would tell you that something odd is happening:
use strict; use warnings; my $notAnInt = '#10'; print "It's 10\n" if $notAnInt == 10; print "It's 0\n" if $notAnInt == 0; print "It's #10\n" if $notAnInt eq '#10';
prints:
Argument "#10" isn't numeric in numeric eq (==) at noname1.pl line 6. It's 0 It's #10
Note that a non-numeric string tends to be numified as 0.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perl typecasting
by perl_junkie (Acolyte) on Feb 04, 2008 at 22:23 UTC | |
by swampyankee (Parson) on Feb 04, 2008 at 23:29 UTC | |
by TGI (Parson) on Feb 05, 2008 at 01:26 UTC | |
by Anonymous Monk on Feb 05, 2008 at 00:25 UTC | |
by perl_junkie (Acolyte) on Feb 05, 2008 at 00:43 UTC |