applied patch, with indentation tweaks
[p5sagit/p5-mst-13.2.git] / pod / perlref.pod
index cf79365..34c071f 100644 (file)
@@ -15,9 +15,9 @@ hashes, hashes of arrays, arrays of hashes of functions, and so on.
 
 Hard references are smart--they keep track of reference counts for you,
 automatically freeing the thing referred to when its reference count goes
-to zero.  (Note: The reference counts for values in self-referential or
+to zero.  (Note: the reference counts for values in self-referential or
 cyclic data structures may not go to zero without a little help; see
-L<perlobj/"Two-Phased Garbage Collection"> for a detailed explanation.
+L<perlobj/"Two-Phased Garbage Collection"> for a detailed explanation.)
 If that thing happens to be an object, the object is destructed.  See
 L<perlobj> for more about objects.  (In a sense, everything in Perl is an
 object, but we usually reserve the word for references to objects that
@@ -120,6 +120,15 @@ reference to it, you have these options:
     sub hashem {       +{ @_ } }   # ok
     sub hashem { return { @_ } }   # ok
 
+On the other hand, if you want the other meaning, you can do this:
+
+    sub showem {        { @_ } }   # ambiguous (currently ok, but may change)
+    sub showem {       {; @_ } }   # ok
+    sub showem { { return @_ } }   # ok
+
+Note how the leading C<+{> and C<{;> always serve to disambiguate
+the expression to mean either the HASH reference, or the BLOCK.
+
 =item 4.
 
 A reference to an anonymous subroutine can be constructed by using
@@ -318,14 +327,15 @@ it's presumably referencing.  That would be case 3.
 
 =item 3.
 
-The case of individual array elements arises often enough that it gets
-cumbersome to use method 2.  As a form of syntactic sugar, the two
-lines like that above can be written:
+Subroutine calls and lookups of individual array elements arise often
+enough that it gets cumbersome to use method 2.  As a form of
+syntactic sugar, the examples for method 2 may be written:
 
-    $arrayref->[0] = "January";
-    $hashref->{"KEY"} = "VALUE";
+    $arrayref->[0] = "January";   # Array element
+    $hashref->{"KEY"} = "VALUE";  # Hash element
+    $coderef->(1,2,3);            # Subroutine call
 
-The left side of the array can be any expression returning a reference,
+The left side of the arrow can be any expression returning a reference,
 including a previous dereference.  Note that C<$array[$x]> is I<NOT> the
 same thing as C<$array-E<gt>[$x]> here: