summaryrefslogtreecommitdiff
path: root/pod/perldata.pod
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>2000-02-15 17:05:12 +0000
committerGurusamy Sarathy <gsar@cpan.org>2000-02-15 17:05:12 +0000
commit56d7751aa4c2e1e56296cbd71ecc38fb6fe74276 (patch)
tree953fba7115b03ffb5aa4ec6610ee6e9052002862 /pod/perldata.pod
parente1354ed68ddc3be6c54faf84ceb7c061bc2941c4 (diff)
downloadperl-56d7751aa4c2e1e56296cbd71ecc38fb6fe74276.tar.gz
doc patches from Rick Delaney and Chris Nandor; update Todo-5.6
p4raw-id: //depot/perl@5102
Diffstat (limited to 'pod/perldata.pod')
-rw-r--r--pod/perldata.pod23
1 files changed, 12 insertions, 11 deletions
diff --git a/pod/perldata.pod b/pod/perldata.pod
index 0b83214a73..a122d34c80 100644
--- a/pod/perldata.pod
+++ b/pod/perldata.pod
@@ -600,16 +600,16 @@ of how to arrange for an output ordering.
=head2 Slices
-A common way access an array or a hash is one scalar element at a time.
-You can also subscript a list to get a single element from it.
+A common way to access an array or a hash is one scalar element at a
+time. You can also subscript a list to get a single element from it.
$whoami = $ENV{"USER"}; # one element from the hash
$parent = $ISA[0]; # one element from the array
$dir = (getpwnam("daemon"))[7]; # likewise, but with list
A slice accesses several elements of a list, an array, or a hash
-simultaneously using a list of subscripts. It's a more convenient
-that writing out the individual elements as a list of separate
+simultaneously using a list of subscripts. It's more convenient
+than writing out the individual elements as a list of separate
scalar values.
($him, $her) = @folks[0,-1]; # array slice
@@ -633,8 +633,8 @@ The previous assignments are exactly equivalent to
($folks[0], $folks[-1]) = ($folks[0], $folks[-1]);
Since changing a slice changes the original array or hash that it's
-slicing, a C<foreach> construct will alter through some--or even
-all--of the values of the array or hash.
+slicing, a C<foreach> construct will alter some--or even all--of the
+values of the array or hash.
foreach (@array[ 4 .. 10 ]) { s/peter/paul/ }
@@ -644,15 +644,16 @@ all--of the values of the array or hash.
s/(\w+)/\u\L$1/g; # "titlecase" words
}
-You couldn't just loop through C<values %hash> to do this because
-that function produces a new list which is a copy of the values,
-so changing them doesn't change the original.
-
A slice of an empty list is still an empty list. Thus:
@a = ()[1,0]; # @a has no elements
@b = (@a)[0,1]; # @b has no elements
- @b = (1,undef)[1,0,1]; # @b has three elements
+ @c = (0,1)[2,3]; # @c has no elements
+
+But:
+
+ @a = (1)[1,0]; # @a has two elements
+ @b = (1,undef)[1,0,2]; # @b has three elements
This makes it easy to write loops that terminate when a null list
is returned: