summaryrefslogtreecommitdiff
path: root/pod/perldiag.pod
diff options
context:
space:
mode:
authorKevin Ryde <user42@zip.com.au>2011-07-24 21:08:15 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-07-24 21:10:59 -0700
commit16546e45435f334cb76d83d4b33f1e01041a9aab (patch)
treef6dbf5469f6ee61ec01645d5fe1f2bffbd904c88 /pod/perldiag.pod
parent6027ee478b8d28c43e93e742f6cce6ac6da97a4d (diff)
downloadperl-16546e45435f334cb76d83d4b33f1e01041a9aab.tar.gz
[perl #95538] perldiag.pod on defined %hash
I found the perldiag.pod description of item "defined(%hash) is deprecated" unclear. At first I thought it was threatening another incompatible change, but if I'm not mistaken it's merely that defined %hash has only ever been a check for non-empty, which may not be what you intended. If so then perhaps a wording like the following could make it clearer,
Diffstat (limited to 'pod/perldiag.pod')
-rw-r--r--pod/perldiag.pod17
1 files changed, 14 insertions, 3 deletions
diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index 483d164f49..5bf28c8bcc 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -1517,9 +1517,20 @@ array is empty, just use C<if (@array) { # not empty }> for example.
=item defined(%hash) is deprecated
-(D deprecated) defined() is not usually useful on hashes because it
-checks for an undefined I<scalar> value. If you want to see if the hash
-is empty, just use C<if (%hash) { # not empty }> for example.
+(D deprecated) C<defined()> is not usually useful on hashes; it merely
+checks for non-empty, similar to a hash in boolean context (see
+L<perldata>). If a non-empty check is what you want then just use:
+
+ if (%hash) {
+ # not empty
+ }
+
+If you had C<defined(%Foo::Bar::QUUX)> to check whether such a
+package variable exists, then it has never actually done that,
+but instead creates the hash if necessary (autovivification)
+then tests for non-empty. If you really want to check
+existence of a package variable then look at the glob slot
+with C<defined *Foo::Bar::QUUX{HASH}> (see L<perlref>).
=item (?(DEFINE)....) does not allow branches in regex; marked by <-- HERE in m/%s/