xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:
Obviously,perl will truncate all spaces before number when it treats a string as a number.No offense,I was wondering why perl develper don't add type declaration(such as num,str).At least, It will help perl beginner not falling many pitfalls like above.use strict; use warnings; my $num1 = 4; my $str1 = "4"; my $str2 = " 4"; print "number \$num1 is equal to string \$str2!!\n"if $num1 == $str2; print "number \$num1 is equal to string \$str1!!\n" if $num1 == $str1; print "string \$num1 is equal to string str2 !!\n" if $num1 eq $str2; print "string \$num1 is equal to string str1 !!\n" if $num1 eq $str1; __OUTPUT__ number $num1 is equal to string $str2!! number $num1 is equal to string $str1!! string $num1 is equal to string str1 !!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: implicit data type exchange
by GrandFather (Saint) on Jan 10, 2007 at 08:28 UTC | |
|
Re: implicit data type exchange
by jbert (Priest) on Jan 10, 2007 at 09:42 UTC | |
|
Re: implicit data type exchange
by Anonymous Monk on Jan 10, 2007 at 08:42 UTC | |
|
Re: implicit data typecast
by xiaoyafeng (Deacon) on Jan 10, 2007 at 10:51 UTC | |
by wazoox (Prior) on Jan 10, 2007 at 11:53 UTC | |
by ww (Archbishop) on Jan 10, 2007 at 14:12 UTC |