develooper Front page | perl.perl5.porters | Postings from June 2004

[PATCH] perlop.pod: add an example to the .. and ... operators

Thread Next
From:
Shlomi Fish
Date:
June 15, 2004 00:15
Subject:
[PATCH] perlop.pod: add an example to the .. and ... operators
Message ID:
Pine.LNX.4.56.0406151013140.14618@vipe.technion.ac.il
--- original/pod/perlop.pod	2004-06-15 09:33:14.340679568 +0300
+++ revised/pod/perlop.pod	2004-06-15 09:49:27.079800744 +0300
@@ -532,7 +532,27 @@
         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

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About