develooper Front page | perl.perl5.porters | Postings from May 2004

Re: undef loses it magicness when assigned to a variable?

Thread Previous | Thread Next
From:
Gisle Aas
Date:
May 27, 2004 01:51
Subject:
Re: undef loses it magicness when assigned to a variable?
Message ID:
lrlljeqmmk.fsf@caliper.activestate.com
Stas Bekman <stas@stason.org> writes:

> Why the ideas always come a second after hitting the send button. The
> obvious thing I was missing is to check how pp_defined does the
> thing. I shouldn't have been wasting time searching in the docs :)
> 
> Stas Bekman wrote:
> [...]
> > So how do I check in C whether the passed variable (or a random sv)
> > is undef or not if comparing to &PL_sv_undef doesn't work?
> 
> So I've changed:
> 
> - ST(0) == &PL_sv_undef
> + (!ST(1) || !SvANY(ST(1))
> 
> and voila, it works whether I call:
> 
>    foo(undef);
> 
> or
> 
>    $x = undef;
>    foo($x);

But it is also wrong as it does not work if you do:

     $x = "foo";
     undef($x);
     foo($x);

if you look closer you will see that pp_defined calls SvOK().  The
SvANY() check is just an optimization.  Just use SvOK(ST(1)) and you
should be ok.

--Gisle

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