diff options
author | Michael G Schwern <schwern@pobox.com> | 1999-10-02 22:34:01 -0400 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 1999-10-03 11:31:22 +0000 |
commit | e0478e5a74c23ab803d1f4136ac0e84a68ba9ecf (patch) | |
tree | 2730cb2c39c3841720ef003396a41a5051796d8d /pod/perlref.pod | |
parent | 277427cf4e56f8c457d0805b2bd9ffb88d75e5a5 (diff) | |
download | perl-e0478e5a74c23ab803d1f4136ac0e84a68ba9ecf.tar.gz |
Re: Should keys in pseudo-hashes -always- exist? [DOC PATCH]
To: perl5-porters@perl.org
Message-ID: <19991003023401.A1520@blackrider>
p4raw-id: //depot/cfgperl@4293
Diffstat (limited to 'pod/perlref.pod')
-rw-r--r-- | pod/perlref.pod | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/pod/perlref.pod b/pod/perlref.pod index 5958a7233c..08a2b42aee 100644 --- a/pod/perlref.pod +++ b/pod/perlref.pod @@ -563,6 +563,25 @@ or try to access nonexistent fields. For better performance, Perl can also do the translation from field names to array indices at compile time for typed object references. See L<fields>. +There are two ways to check for the existance of a key in a +pseudo-hash. The first is to use exists(). This checks to see if the +given field has been used yet. It acts this way to match the behavior +of a regular hash. For instance: + + $phash = [{foo =>, bar => 2, pants => 3}, 'FOO']; + $phash->{pants} = undef; + + exists $phash->{foo}; # true, 'foo' was set in the declaration + exists $phash->{bar}; # false, 'bar' has not been used. + exists $phash->{pants}; # true, your 'pants' have been touched + +The second is to use exists() on the hash reference sitting in the +first array element. This checks to see if the given key is a valid +field in the pseudo-hash. + + exists $phash->[0]{pants}; # true, 'pants' is a valid field + exists $phash->[0]{shoes}; # false, 'shoes' can't be used + =head2 Function Templates As explained above, a closure is an anonymous function with access to the |