From 9adebda4fef8cbc5965f9327c10fca15b814f305 Mon Sep 17 00:00:00 2001 From: Stas Bekman Date: Thu, 27 May 2004 04:25:08 -0700 Subject: [PATCH] Re: undef loses it magicness when assigned to a variable? Message-ID: <40B63284.5040203@stason.org> p4raw-id: //depot/perl@22853 --- pod/perlapi.pod | 3 ++- pod/perlguts.pod | 19 ++++++++++++++++--- sv.h | 3 ++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/pod/perlapi.pod b/pod/perlapi.pod index 27daa64..d1ae530 100644 --- a/pod/perlapi.pod +++ b/pod/perlapi.pod @@ -3196,7 +3196,8 @@ Found in file sv.h =item SvOK -Returns a boolean indicating whether the value is an SV. +Returns a boolean indicating whether the value is an SV. It also tells +whether the value is defined or not. bool SvOK(SV* sv) diff --git a/pod/perlguts.pod b/pod/perlguts.pod index 9932b37..99c79d0 100644 --- a/pod/perlguts.pod +++ b/pod/perlguts.pod @@ -201,9 +201,22 @@ you can call: SvOK(SV*) The scalar C value is stored in an SV instance called C. -Its address can be used whenever an C is needed. -However, you have to be careful when using C<&PL_sv_undef> as a value in AVs -or HVs (see L). + +Its address can be used whenever an C is needed. Make sure that +you don't try to compare a random sv with C<&PL_sv_undef>. For example +when interfacing Perl code, it'll work correctly for: + + foo(undef); + +But won't work when called as: + + $x = undef; + foo($x); + +So to repeat always use SvOK() to check whether an sv is defined. + +Also you have to be careful when using C<&PL_sv_undef> as a value in +AVs or HVs (see L). There are also the two values C and C, which contain boolean TRUE and FALSE values, respectively. Like C, their diff --git a/sv.h b/sv.h index fab44eb..4edd87f 100644 --- a/sv.h +++ b/sv.h @@ -410,7 +410,8 @@ double. Checks the B setting. Use C. Unsets the NV/IV status of an SV. =for apidoc Am|bool|SvOK|SV* sv -Returns a boolean indicating whether the value is an SV. +Returns a boolean indicating whether the value is an SV. It also tells +whether the value is defined or not. =for apidoc Am|bool|SvIOKp|SV* sv Returns a boolean indicating whether the SV contains an integer. Checks -- 2.7.4