Skip to content

Commit

Permalink
Verbose explaination of the range operators.
Browse files Browse the repository at this point in the history
Since, so far, pod tables cannot deal with C<>, I switched the table of
range operators to a list of items with a specific code example following.
  • Loading branch information
fluca1978 committed Dec 18, 2017
1 parent 5801be3 commit b26526f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions doc/Language/5to6-perlop.pod6
Expand Up @@ -161,16 +161,20 @@ In list context, C<..> operates as the range operator and should not
need to be changed. That said, there are exclusionary range operators
that may be useful. These are:
=begin table
=item infix C<..^> which excludes the endpoint;
=item infix ^.. which excludes the starting point;
=item infix C<^..^> which excludes both the starting and ending points;
=item prefix C<^> which starts from zero excluding the endpoint.
Mode Op Description
====== ==== ============
infix ..^ Excludes endpoint. C<1..^5>; # 1 2 3 4 >
infix ^.. Excludes starting point. C<1^..5>; # 2 3 4 5>
infix ^..^ Excludes both starting and endpoint. C<1^..^5>; # 2 3 4>
prefix ^ From 0, excludes endpoint. C<^5>; # 0 1 2 3 4>
The following example shows the effects of all the above range operators
(please note parentheses are used only to allow the method call):
=end table
=begin code
(1..^5).list; # (1 2 3 4)
(1^..5).list; # (2 3 4 5)
(1^..^5).list; # (2 3 4)
(^5).list; # (0 1 2 3 4)
=end code
In scalar context, C<..> and C<...> work as flip-flop operators in Perl
5, but are little-known, and probably even less used. Those operations
Expand Down

0 comments on commit b26526f

Please sign in to comment.