X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlfunc.pod;h=dbefd85ee438c7de358949b019c896efab880b38;hb=2decb4fb82e001e3c9671c57b61232c651a9c22c;hp=d730b43e47eecc667f68e74104209479d4c7f56e;hpb=f472eb5c07ed95306a11c98250bda17aae994339;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index d730b43..dbefd85 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -1422,8 +1422,16 @@ element is not autovivified if it doesn't exist. A hash or array element can be true only if it's defined, and defined if it exists, but the reverse doesn't necessarily hold true. +Given an expression that specifies the name of a subroutine, +returns true if the specified subroutine has ever been declared, even +if it is undefined. Mentioning a subroutine name for exists or defined +does not count as declaring it. + + print "Exists\n" if exists &subroutine; + print "Defined\n" if defined &subroutine; + Note that the EXPR can be arbitrarily complicated as long as the final -operation is a hash or array key lookup: +operation is a hash or array key lookup or subroutine name: if (exists $ref->{A}->{B}->{$key}) { } if (exists $hash{A}{B}{$key}) { } @@ -1431,6 +1439,8 @@ operation is a hash or array key lookup: if (exists $ref->{A}->{B}->[$ix]) { } if (exists $hash{A}{B}[$ix]) { } + if (exists &{$ref->{A}{B}{$key}}) { } + Although the deepest nested array or hash will not spring into existence just because its existence was tested, any intervening ones will. Thus C<$ref-E{"A"}> and C<$ref-E{"A"}-E{"B"}> will spring @@ -1448,6 +1458,12 @@ release. See L for specifics on how exists() acts when used on a pseudo-hash. +Use of a subroutine call, rather than a subroutine name, as an argument +to exists() is an error. + + exists ⊂ # OK + exists &sub(); # Error + =item exit EXPR Evaluates EXPR and exits immediately with that value. Example: