develooper Front page | perl.dbi.dev | Postings from April 2002

Re: DBI::PurePerl -- would you believe 100%?

From:
merlyn
Date:
April 13, 2002 08:25
Subject:
Re: DBI::PurePerl -- would you believe 100%?
Message ID:
m1vgav1uzx.fsf@halfdome.holdit.com
>>>>> "Randal" == Randal L Schwartz <merlyn@stonehenge.com> writes:

>>>>> "Jeff" == Jeff Zucker <jeff@vpservices.com> writes:
Jeff> * skipped 2 of the subtests on neat() which depend on 
Jeff> looks_like_number() telling the difference between "2"
Jeff> and 2

Randal> This *is* possible in Pure Perl.  Depends on the property that a
Randal> string that hasn't been used in a numeric context reacts differently
Randal> to the bit operators. The exact idiom escapes me at the moment, but I
Randal> *could* find it if properly prodded.

Found it after playing around for a few minutes.  I hope this is it, anyway:

        sub is_numeric {
                ($_[0] & ~ $_[0]) eq "0";
        }

Returns true for 2, false for "2".

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!



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