On Sat, Jun 14, 2003 at 08:56:21AM -0500 deborah wrote: > How does Perl interpret a string when used in a numeric comparison > equation?
It depends. > I accidently used a numeric comparison operator when I was comparing > strings and I found that no matter what strings I compared, Perl always > said they were equal. In that case, both certainly evaluated to the same numerical value. For instance, this comparison is true: "14b" == "14c" # in numerical context both are evaluated as 14 this one as well: "b14" == "c14" # in numberical both are evaluated as 0 And subsequently: "14b" != "b14" # because 14 != 0 > Any other operation (such as <, >, != ) always proved false, but it was > always true that 'stringA'=='Bstrg'. Is it just saying that "it is > true" that stringA and Bstrg are both strings? I thought it would count > spaces or convert to numbers or something like that. Well, actually, I > first was surprised that it didn't give me an error since I used the > wrong type of operator. What is it doing in this case? It's not an error in Perl. But you get a warning if you 'use warnings' or employ the -w switch: perl -we 'print "14b" == "14c"' Argument "14c" isn't numeric in numeric eq (==) at -e line 1. Argument "14b" isn't numeric in numeric eq (==) at -e line 1. 1 As a rule of thumb: perl takes the longest numerical prefix of a string and treats it as number (either integer or float). In the following, numeric context is enforced by adding 0 to a string: print "$_"+0, "\n" for "2", "2a", "2.2", "2.2a", "a2", "a2.2"; __END__ 2 2 2.2 2.2 But: print "4e10"+0; __END__ 40000000000 because 4e10 is a number in scientific notation and therefore a valid number literal. Tassilo -- $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({ pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#; $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]