perl 5.003_06: sv.h
[p5sagit/p5-mst-13.2.git] / pod / perllol.pod
index 4b58bee..c97aac9 100644 (file)
@@ -1,8 +1,10 @@
-=head1 TITLE
+=head1 NAME
 
 perlLoL - Manipulating Lists of Lists in Perl
 
-=head1 Declaration and Access
+=head1 DESCRIPTION
+
+=head1 Declaration and Access of Lists of Lists
 
 The simplest thing to build is a list of lists (sometimes called an array
 of arrays).  It's reasonably easy to understand, and almost everything
@@ -10,7 +12,7 @@ that applies here will also be applicable later on with the fancier data
 structures.
 
 A list of lists, or an array of an array if you would, is just a regular
-old array @LoL that you can get at with two subscripts, like $LoL[3][2].  Here's
+old array @LoL that you can get at with two subscripts, like C<$LoL[3][2]>.  Here's
 a declaration of the array:
 
     # assign to our array a list of list references
@@ -40,7 +42,7 @@ but rather just a reference to it, you could do something more like this:
 Notice that the outer bracket type has changed, and so our access syntax 
 has also changed.  That's because unlike C, in perl you can't freely
 interchange arrays and references thereto.  $ref_to_LoL is a reference to an 
-array, whereas @LoL is an array proper.  Likewise, $LoL[2] is not an 
+array, whereas @LoL is an array proper.  Likewise, C<$LoL[2]> is not an 
 array, but an array ref.  So how come you can write these:
 
     $LoL[2][2]
@@ -52,8 +54,8 @@ instead of having to write these:
     $ref_to_LoL->[2]->[2]
 
 Well, that's because the rule is that on adjacent brackets only (whether
-square or curly), you are free to omit the pointer dereferencing array.
-But you need not do so for the very first one if it's a scalar containing
+square or curly), you are free to omit the pointer dereferencing arrow.
+But you cannot do so for the very first one if it's a scalar containing
 a reference, which means that $ref_to_LoL always needs it.
 
 =head1 Growing Your Own
@@ -114,7 +116,7 @@ You also don't have to use push().  You could just make a direct assignment
 if you knew where you wanted to put it:
 
     my (@LoL, $i, $line);
-    for $i ( 0 .. 10 ) 
+    for $i ( 0 .. 10 ) {
        $line = <>;
        $LoL[$i] = [ split ' ', $line ];
     } 
@@ -122,16 +124,16 @@ if you knew where you wanted to put it:
 or even just
 
     my (@LoL, $i);
-    for $i ( 0 .. 10 ) 
+    for $i ( 0 .. 10 ) {
        $LoL[$i] = [ split ' ', <> ];
     } 
 
-You should in general be leary of using potential list functions
+You should in general be leery of using potential list functions
 in a scalar context without explicitly stating such.  
 This would be clearer to the casual reader:
 
     my (@LoL, $i);
-    for $i ( 0 .. 10 ) 
+    for $i ( 0 .. 10 ) {
        $LoL[$i] = [ split ' ', scalar(<>) ];
     } 
 
@@ -241,7 +243,7 @@ Hm... that's still a bit ugly.  How about this:
 
 =head1 Slices
 
-If you want to get at a slide (part of a row) in a multidimensional
+If you want to get at a slice (part of a row) in a multidimensional
 array, you're going to have to do some fancy subscripting.  That's
 because while we have a nice synonym for single elements via the
 pointer arrow for dereferencing, no such convenience exists for slices.
@@ -300,54 +302,12 @@ If I were you, I'd put that in a function:
     } 
 
 
-=head1 Passing Arguments
-
-One place where a list of lists crops up is when you pass
-in several list references to a function.  Consider:
-
-    @tailings = popmany ( \@a, \@b, \@c, \@d );
-
-    sub popmany {
-       my $aref;
-       my @retlist = ();
-       foreach $aref ( @_ ) {
-           push @retlist, pop @$aref;
-       } 
-       return @retlist;
-    } 
-
-This function was designed to pop off the last element from each of
-its arguments and return those in a list.  In this function, 
-you can think of @_ as a list of lists.
-
-Just as a side note, what happens if the function is called with the
-"wrong" types of arguments?  Normally nothing, but in the case of
-references, we can be a bit pickier.  This isn't detectable at
-compile-time (yet--Larry does have a prototype prototype in the works for
-5.002), but you could check it at run time using the ref() function.
-
-    use Carp;
-    for $i ( 0 .. $#_) {
-       if (ref($_[$i]) ne 'ARRAY') {
-           confess "popmany: arg $i not an array reference\n";
-       }
-    } 
-
-However, that's not usually necessary unless you want to trap it.  It's
-also dubious in that it would fail on a real array references blessed into
-its own class (an object).  But since you're all going to be using
-C<strict refs>, it would raise an exception anyway even without the die.
-
-This will matter more to you later on when you start building up 
-more complex data structures that all aren't woven of the same 
-cloth, so to speak.
-
 =head1 SEE ALSO
 
 perldata(1), perlref(1), perldsc(1)
 
 =head1 AUTHOR
 
-Tom Christiansen <tchrist@perl.com>
+Tom Christiansen E<lt>F<tchrist@perl.com>E<gt>
 
 Last udpate: Sat Oct  7 19:35:26 MDT 1995