develooper Front page | | Postings from April 2002

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

April 13, 2002 08:25
Re: DBI::PurePerl -- would you believe 100%?
Message ID:
>>>>> "Randal" == Randal L Schwartz <> writes:

>>>>> "Jeff" == Jeff Zucker <> 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
<> <URL:>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See for onsite and open-enrollment Perl training! Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About