X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlref.pod;h=f738399c9a97391ece56cd3379c56d8a566855b7;hb=ce32ed4b46e58900e04971fb3189c48cd1fadbd1;hp=08a2b42aee6d893b882bcfc162f719e27c1c25cc;hpb=e0478e5a74c23ab803d1f4136ac0e84a68ba9ecf;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlref.pod b/pod/perlref.pod index 08a2b42..f738399 100644 --- a/pod/perlref.pod +++ b/pod/perlref.pod @@ -558,29 +558,39 @@ to array indices. Here is an example: print "$k => $v\n"; } -Perl will raise an exception if you try to delete keys from a pseudo-hash -or try to access nonexistent fields. For better performance, Perl can also +Perl will raise an exception if you 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. -There are two ways to check for the existance of a key in a +There are two ways to check for the existence 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 +given field has ever been set. It acts this way to match the behavior of a regular hash. For instance: - $phash = [{foo =>, bar => 2, pants => 3}, 'FOO']; + $phash = [{foo =>1, 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 + print exists $phash->{foo}; # true, 'foo' was set in the declaration + print exists $phash->{bar}; # false, 'bar' has not been used. + print 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 + print exists $phash->[0]{bar}; # true, 'bar' is a valid field + print exists $phash->[0]{shoes};# false, 'shoes' can't be used + +delete() on a pseudo-hash element only deletes the value corresponding +to the key, not the key itself. To delete the key, you'll have to +explicitly delete it from the first hash element. + + print delete $phash->{foo}; # prints $phash->[1], "FOO" + print exists $phash->{foo}; # false + print exists $phash->[0]{foo}; # true, key still exists + print delete $phash->[0]{foo}; # now key is gone + print $phash->{foo}; # runtime exception =head2 Function Templates