develooper Front page | perl.beginners | Postings from April 2002

Strings as Numbers (was: Re: simple problem)

Thread Previous | Thread Next
From:
Todd Wade
Date:
April 30, 2002 15:19
Subject:
Strings as Numbers (was: Re: simple problem)
Message ID:
20020430221930.96096.qmail@onion.perl.org

"Jeffrey Seger" <Jeffrey.Seger@fairchildsemi.com> wrote in message
news:OF8797ADBF.37DC6BE5-ON85256BAA.005717B1@fairchildsemi.com...
>
> if ( $tablename > 1) is going to evaluate to false since the numeric value
> of any string is 1.

Actually, its a little more complicated than this.

A string that starts with non-numeric alphanumeric characters evaluates to 0
when used in numeric context.

perl -e 'print "aaa123" + 1;' # prints 1

but when a string starts with numeric characters, evaluates to the number
before the first non-numeric alphanumeric number:

perl -e 'print "123aaa" + 1;' # woah !!! prints 124 !!!

Actually, its even a little more complicated than that.

Todd Wade
trw3@uakron.edu





Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About