in reply to DBI: when 1 != '1'

Interesting... very interesting. So what happens for values that are both numbers and strings? I just ran your is_number() trick against a string/number variable (actually a PVIV) and it correctly reported that there it's a number... it just also happens to be a string.

use Devel::Peek; $a = 0; scalar "$a"; Dump($a); # prove it's a PVIV with IOK and POK set print is_number($a); # returns true sub is_number { ( $_[0] & ~ $_[0] ) eq '0' }

Replies are listed 'Best First'.
Re^2: DBI: when 1 != '1'
by Aristotle (Chancellor) on Sep 27, 2002 at 17:51 UTC

    The ~ operator has to decide whether to treat the scalar as a string or as a numeric. I would say it makes a lot of sense to prefer numeric treatment whenever that flag's set - as it's likely that a number that's also string is really a stringified number, and not that likely that it's a numified string.

    So long as any XS or otherwise non-Perl code plays by the same rule, you're not going to run into trouble with that situation.

    Makeshifts last the longest.