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

[PATCH doc] Re: undef loses it magicness when assigned to a variable?

Thread Previous | Thread Next
From:
Stas Bekman
Date:
May 27, 2004 11:25
Subject:
[PATCH doc] Re: undef loses it magicness when assigned to a variable?
Message ID:
40B63284.5040203@stason.org
Thanks Tony, Tim and Gisle for the explanations. Here are the doc patches. 
Attached and inlined

--- sv.h.orig	2004-05-27 11:21:30.003151581 -0700
+++ sv.h	2004-05-27 11:22:18.316840312 -0700
@@ -410,7 +410,8 @@
  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
--- pod/perlguts.pod.orig	2004-05-27 11:16:15.031296694 -0700
+++ pod/perlguts.pod	2004-05-27 11:21:09.135877496 -0700
@@ -201,9 +201,22 @@
      SvOK(SV*)

  The scalar C<undef> value is stored in an SV instance called C<PL_sv_undef>.
-Its address can be used whenever an C<SV*> is needed.
-However, you have to be careful when using C<&PL_sv_undef> as a value in AVs
-or HVs (see L<AVs, HVs and undefined values>).
+
+Its address can be used whenever an C<SV*> 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<AVs, HVs and undefined values>).

  There are also the two values C<PL_sv_yes> and C<PL_sv_no>, which contain
  boolean TRUE and FALSE values, respectively.  Like C<PL_sv_undef>, their

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

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