On Jul 21, 2004, at 3:16 AM, Sisyphus wrote:

Why does 'looks_like_number()' report that an SvRV looks like a number ?

i'm going to make a wild guess and say that it's probably something like RV's hold the address of something else, which is like a number.


according to the source of perl 5.8.0 (which i just happen to have lying around), Perl_looks_like_number (at sv.c:1849) checks to see if you have a PV, and if so extracts the string and calls grok_number() on it (Perl_grok_number, at numeric.c:530, handles only char* strings). for all other types, it returns 1; the comment there says "Historic. Wrong?".

to me, that says that this function probably dates back to before there were RVs, and assumes that if it's not a PV, it's an NV or an IV, and those are obviously numbers. the exhaustive check only needs to be performed on strings. it may be wrong to perform this on a CV or RV, but since you can check that before calling looks_like_number() with any of the flag-checking macros, it was probably not deemed important to put that logic into this function. after all, does it make sense to see if a pointer is a number?


If I wanted to know if a variable is a valid number, I would like references to be rejected - hence I would have to be coding:
if(looks_like_number(y) && !SvROK(y)) /* it's valid */

minor point, but it would be more efficient to short circuit this test on references, since that's just a a simple flag check, e.g.:


   if(!SvROK(y) && looks_like_number(y)) /* it's valid */




--
How come hair colors for women take an hour, but "wash out the gray" stuff for men only five minutes? This is so unfair!
-- Elysse, complaining about commercials




Reply via email to