From 16546e45435f334cb76d83d4b33f1e01041a9aab Mon Sep 17 00:00:00 2001 From: Kevin Ryde Date: Sun, 24 Jul 2011 21:08:15 -0700 Subject: [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, --- pod/perldiag.pod | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'pod') 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 for example. =item defined(%hash) is deprecated -(D deprecated) defined() is not usually useful on hashes because it -checks for an undefined I value. If you want to see if the hash -is empty, just use C for example. +(D deprecated) C is not usually useful on hashes; it merely +checks for non-empty, similar to a hash in boolean context (see +L). If a non-empty check is what you want then just use: + + if (%hash) { + # not empty + } + +If you had C 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 (see L). =item (?(DEFINE)....) does not allow branches in regex; marked by <-- HERE in m/%s/ -- cgit v1.2.1