X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlreftut.pod;h=83e6aa8bd32e3b95691504a4c0603a59709c9d5e;hb=cccede5366275457276b68bb148b7872098aaf29;hp=4526e4a2a0d7c57f81fecd5aca2ebbbe1122ccda;hpb=1da6492a14ea9ac9ef7bba383eb87fa8ea512acc;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlreftut.pod b/pod/perlreftut.pod index 4526e4a..83e6aa8 100644 --- a/pod/perlreftut.pod +++ b/pod/perlreftut.pod @@ -65,14 +65,14 @@ references. A reference is a scalar value that I an entire array or an entire hash (or to just about anything else). Names are one kind of -reference that you're already familiar with. Think of the President: -a messy, inconvenient bag of blood and bones. But to talk about him, -or to represent him in a computer program, all you need is the easy, -convenient scalar string "Bill Clinton". +reference that you're already familiar with. Think of the President +of the United States: a messy, inconvenient bag of blood and bones. +But to talk about him, or to represent him in a computer program, all +you need is the easy, convenient scalar string "George Bush". References in Perl are like names for arrays and hashes. They're Perl's private, internal names, so you can be sure they're -unambiguous. Unlike "Bill Clinton", a reference only refers to one +unambiguous. Unlike "George Bush", a reference only refers to one thing, and you always know what it refers to. If you have a reference to an array, you can recover the entire array from it. If you have a reference to a hash, you can recover the entire hash. But the @@ -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! @@ -336,11 +336,11 @@ other references. =item * -In B, you can omit the curly braces whenever the thing +In B, you can omit the curly brackets whenever the thing inside them is an atomic scalar variable like C<$aref>. For example, C<@$aref> is the same as C<@{$aref}>, and C<$$aref[1]> is the same as C<${$aref}[1]>. If you're just starting out, you may want to adopt -the habit of always including the curly braces. +the habit of always including the curly brackets. =item * @@ -386,10 +386,10 @@ 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. +( http://www.tpj.com/ ) volume 3, #2. Reprinted with permission. The original title was I.