summaryrefslogtreecommitdiff
path: root/pod
diff options
context:
space:
mode:
authorShlomi Fish <shlomif@vipe.technion.ac.il>2004-06-15 13:15:15 +0300
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2004-06-15 08:22:32 +0000
commitacf31ca582944c8bb9501bdc43ade24d8a322e8a (patch)
tree563baed62330c9f121186c26b34084b02556da00 /pod
parent2649f2c19a9dc4cac2cf535de25fe7b36dee8328 (diff)
downloadperl-acf31ca582944c8bb9501bdc43ade24d8a322e8a.tar.gz
perlop.pod: add an example to the .. and ... operators
Message-ID: <Pine.LNX.4.56.0406151013140.14618@vipe.technion.ac.il> p4raw-id: //depot/perl@22936
Diffstat (limited to 'pod')
-rw-r--r--pod/perlop.pod22
1 files changed, 21 insertions, 1 deletions
diff --git a/pod/perlop.pod b/pod/perlop.pod
index 4430fe7609..6f8e2dd0b7 100644
--- a/pod/perlop.pod
+++ b/pod/perlop.pod
@@ -532,7 +532,27 @@ As a scalar operator:
close ARGV if eof; # reset $. each file
}
-As a list operator:
+Here's a simple example to illustrate the difference between
+the two range operators:
+
+ @lines = (" - Foo",
+ "01 - Bar",
+ "1 - Baz",
+ " - Quux");
+
+ foreach(@lines)
+ {
+ if (/0/ .. /1/)
+ {
+ print "$_\n";
+ }
+ }
+
+This program will print only the line containing "Bar". If
+the range operator is changed to C<...>, it will also print the
+"Baz" line.
+
+And now some examples as a list operator:
for (101 .. 200) { print; } # print $_ 100 times
@foo = @foo[0 .. $#foo]; # an expensive no-op