X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlreftut.pod;h=073d358da55e867a146cba837b8bb88afb890e15;hb=5269aecde866056a77e32c937c7c3182bb599487;hp=09bea594ff4e9819a98ed665f9988a5ceafb11fd;hpb=d98d5fffa337682ca6cac752b32ff55e863a53a0;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlreftut.pod b/pod/perlreftut.pod index 09bea59..073d358 100644 --- a/pod/perlreftut.pod +++ b/pod/perlreftut.pod @@ -184,26 +184,26 @@ Using a hash reference is I the same: B -C<${$aref}[3]> is too hard to read, so you can write C<$aref-E[3]> +C<${$aref}[3]> is too hard to read, so you can write C<< $aref->[3] >> instead. C<${$href}{red}> is too hard to read, so you can write -C<$href-E{red}> instead. +C<< $href->{red} >> instead. Most often, when you have an array or a hash, you want to get or set a single element from it. C<${$aref}[3]> and C<${$href}{'red'}> have too much punctuation, and Perl lets you abbreviate. -If C<$aref> holds a reference to an array, then C<$aref-E[3]> is +If C<$aref> holds a reference to an array, then C<< $aref->[3] >> is the fourth element of the array. Don't confuse this with C<$aref[3]>, which is the fourth element of a totally different array, one deceptively named C<@aref>. C<$aref> and C<@aref> are unrelated the same way that C<$item> and C<@item> are. -Similarly, C<$href-E{'red'}> is part of the hash referred to by +Similarly, C<< $href->{'red'} >> is part of the hash referred to by the scalar variable C<$href>, perhaps even one with no name. C<$href{'red'}> is part of the deceptively named C<%href> hash. It's -easy to forget to leave out the C<-E>, and if you do, you'll get +easy to forget to leave out the C<< -> >>, and if you do, you'll get bizarre results when your program gets array and hash elements out of totally unexpected hashes and arrays that weren't the ones you wanted to use. @@ -228,10 +228,10 @@ another array. C<$a[1]> is one of these references. It refers to an array, the array containing C<(4, 5, 6)>, and because it is a reference to an array, -B says that we can write C<$a[1]-E[2]> to get the -third element from that array. C<$a[1]-E[2]> is the 6. -Similarly, C<$a[0]-E[1]> is the 2. What we have here is like a -two-dimensional array; you can write C<$a[ROW]-E[COLUMN]> to get +B says that we can write C<< $a[1]->[2] >> to get the +third element from that array. C<< $a[1]->[2] >> is the 6. +Similarly, C<< $a[0]->[1] >> is the 2. What we have here is like a +two-dimensional array; you can write C<< $a[ROW]->[COLUMN] >> to get or set the element in any row and any column of the array. The notation still looks a little cumbersome, so there's one more @@ -241,8 +241,8 @@ abbreviation: In between two B, the arrow is optional. -Instead of C<$a[1]-E[2]>, we can write C<$a[1][2]>; it means the -same thing. Instead of C<$a[0]-E[1]>, we can write C<$a[0][1]>; +Instead of C<< $a[1]->[2] >>, we can write C<$a[1][2]>; it means the +same thing. Instead of C<< $a[0]->[1] >>, we can write C<$a[0][1]>; it means the same thing. Now it really looks like two-dimensional arrays! @@ -386,7 +386,7 @@ to do with references. =head1 Credits -Author: Mark-Jason Dominus, Plover Systems (C) +Author: Mark-Jason Dominus, Plover Systems (C) This article originally appeared in I (http://tpj.com) volume 3, #2. Reprinted with permission.