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

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

Thread Previous | Thread Next
From:
Nick Ing-Simmons
Date:
June 1, 2004 09:05
Subject:
Re: undef loses it magicness when assigned to a variable?
Message ID:
20040601160459.7519.6@llama.elixent.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 possibly not for 

    $x = 42;
    ...
    $x = undef;
    foo($x);       # SvANY is probably still an SvIV


>
>> am I missing 
>> some obvious RTFM section? I've read: 'perlguts:=head2 AVs, HVs and 
>> undefined values'
>> but it doesn't seem to be related. There were many other references to 
>> undef in the perl manpages, but I didn't find anything useful.
>
>This should probably be added to the perlguts manpage, next to the
>'=head2 AVs, HVs and  undefined values' item.
>
>=head How to check arguments for undefine-ness
>...


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