On Wednesday, 2 בMay 2007 17:06, Jason Elbaum wrote: > Can anyone explain the following phenomenon, or is it a bug in perl? > print 5 + 7, "\n"; > print "5" + 7, "\n"; > print "5&6" + 7, "\n"; > > The output: > > Argument "5&6" isn't numeric in addition (+) at - line 5. > 12 > 12 > 12
Since you quoted it, it's a string. However, since it is used in numeric context (because of +), Perl tries to convert it to number. Perl conversion work very similar to atof(3) [maybe it even use it, didn't bother to check]. It convert the numeric content of the string and stops conversion when it hits non-numeric characters. That's why "5&6" is converted to 5 in numeric context. And for the same reason the string "hello" is converted to 0 (conversion stops right at the beginning of the string). > So is "5&6" numeric or not? The warning says it isn't, but the > addition evaluates to 12! Shouldn't non-numeric strings evaluate to > zero? Hope it is clear now. -- Oron Peled Voice/Fax: +972-4-8228492 [EMAIL PROTECTED] http://www.actcom.co.il/~oron ICQ UIN: 16527398 May the Source be with you! _______________________________________________ Perl mailing list [email protected] http://perl.org.il/mailman/listinfo/perl
