summaryrefslogtreecommitdiff
path: root/pod/perlref.pod
diff options
context:
space:
mode:
authorGisle Aas <gisle@aas.no>1998-07-03 02:50:15 +0200
committerGurusamy Sarathy <gsar@cpan.org>1998-07-04 03:13:02 +0000
commit49399b3f940d44418e30fbc3c7271b5d4ee63620 (patch)
treecbb23497d8c13d51f51f8471f24274839019dcea /pod/perlref.pod
parent57079c468e190b483eeed1dc905fcaa88d70475e (diff)
downloadperl-49399b3f940d44418e30fbc3c7271b5d4ee63620.tar.gz
added patch, with tweaks
Message-ID: <m3btr7n9zs.fsf@furu.g.aas.no> Subject: [PATCH] Some AVHV documentation p4raw-id: //depot/perl@1287
Diffstat (limited to 'pod/perlref.pod')
-rw-r--r--pod/perlref.pod32
1 files changed, 32 insertions, 0 deletions
diff --git a/pod/perlref.pod b/pod/perlref.pod
index 50400b7807..66b1a7d7c1 100644
--- a/pod/perlref.pod
+++ b/pod/perlref.pod
@@ -511,6 +511,38 @@ The B<-w> switch will warn you if it interprets a reserved word as a string.
But it will no longer warn you about using lowercase words, because the
string is effectively quoted.
+=head2 Pseudo-hashes: Using an array as a hash
+
+WARNING: This section describes an experimental feature. Details may
+change without notice in future versions.
+
+Beginning with release 5.005 of Perl you can use an array reference
+in some contexts that would normally require a hash reference. This
+allows you to access array elements using symbolic names, as if they
+were fields in a structure.
+
+For this to work, the array must contain extra information. The first
+element of the array has to be a hash reference that maps field names
+to array indices. Here is an example:
+
+ $struct = [{foo => 1, bar => 2}, "FOO", "BAR"];
+
+ $struct->{foo}; # same as $struct->[1], i.e. "FOO"
+ $struct->{bar}; # same as $struct->[2], i.e. "BAR"
+
+ keys %$struct; # will return ("foo", "bar") in some order
+ values %$struct; # will return ("FOO", "BAR") in same some order
+
+ while (my($k,$v) = each %$struct) {
+ 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
+do the translation from field names to array indices at compile time for
+typed object references. See L<fields>.
+
+
=head2 Function Templates
As explained above, a closure is an anonymous function with access to the