Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
whitespace
  • Loading branch information
coke committed Jul 9, 2018
1 parent 0c0dc4c commit bc7a753
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions doc/Language/101-basics.pod6
@@ -1,12 +1,12 @@
=begin pod :tag<tutorial> :page-order<A00>
=TITLE Perl 6 Example P6-101
=TITLE Perl 6 Example P6-101
=SUBTITLE A basic introductory example of a Perl 6 program
=SUBTITLE A basic introductory example of a Perl 6 program
Perl originated as a programming language intended to gather and summarize
information from text files. It's still strong in text processing, but Perl 5
is also a powerful general-purpose programming language. Perl 6 is even better.
information from text files. It's still strong in text processing, but Perl 5
is also a powerful general-purpose programming language. Perl 6 is even better.
Suppose that you host a table tennis tournament. The referees tell you the
results of each game in the format C<Player1 Player2 | 3:2>, which means
Expand All @@ -27,7 +27,7 @@ The input data (stored in a file called "scores.txt") looks like this:
The first line is the list of players. Every subsequent line records a result
of a match.
Here's one way to solve that problem in Perl 6:
Here's one way to solve that problem in Perl 6:
=begin code
Expand Down Expand Up @@ -75,13 +75,13 @@ This produces the output:
=head3 X<C<v6>>
Every Perl 6 program should begin with C<use v6;>. This line tells the compiler
Every Perl 6 program should begin with C<use v6;>. This line tells the compiler
which version of Perl the program expects. Should you accidentally run the file
with Perl 5, you'll get a helpful error message.
with Perl 5, you'll get a helpful error message.
=head3 X<C<statement>>
A Perl 6 program consists of zero or more statements. A I<statement> ends with
A Perl 6 program consists of zero or more statements. A I<statement> ends with
a semicolon or a curly bracket at the end of a line:
=begin code
Expand Down Expand Up @@ -142,14 +142,14 @@ the argument provided to C<open>.
=head3 X<C<array>>, X<C<method>> and X<C<invocant>>
The right-hand side calls a I<method> --a named group of behavior-- named C<get>
on the file handle stored in C<$file>. The C<get> method reads and returns
on the file handle stored in C<$file>. The C<get> method reads and returns
one line from the file, removing the line ending. If you print the contents of C<$file>
after calling C<get>, you will see that the first line is no longer in there. C<words> is also a method,
called on the string returned from C<get>. C<words> decomposes its
after calling C<get>, you will see that the first line is no longer in there. C<words> is also a method,
called on the string returned from C<get>. C<words> decomposes its
I<invocant>--the string on which it operates--into a list of words, which
here means strings separated by whitespace.
It turns the single string C<'Beth Ana Charlie Dave'> into the list of
strings C<'Beth', 'Ana', 'Charlie', 'Dave'>.
It turns the single string C<'Beth Ana Charlie Dave'> into the list of
strings C<'Beth', 'Ana', 'Charlie', 'Dave'>.
Finally, this list gets
stored in the array C<@names>. The C<@> sigil marks the declared variable as
Expand All @@ -168,8 +168,8 @@ These two lines of code declare two hashes. The C<%> sigil marks each
variable as a C<Hash>. A C<Hash> is an unordered collection of key-value
pairs. Other programming languages call that a I<hash table>,
I<dictionary>, or I<map>. You can query a hash table for the value that
corresponds to a certain C<$key> with C<%hash{$key}>N<Unlike Perl 5, in
Perl 6 the sigil does not change when accessing an array or hash with
corresponds to a certain C<$key> with C<%hash{$key}>N<Unlike Perl 5, in
Perl 6 the sigil does not change when accessing an array or hash with
C<[ ]> or C<{ }>. This is called X<I<sigil invariance>>.>.
In the score counting program, C<%matches> stores the number of matches each
Expand Down Expand Up @@ -319,7 +319,7 @@ are passed in through the I<topic variable> C<$_>.
You have seen blocks before: both the C<for> loop C<< -> $line { ... } >> and
the C<if> statement worked on blocks. A block is a self-contained piece of
Perl 6 code with an optional signature (the C<< -> $line >> part). See
Perl 6 code with an optional signature (the C<< -> $line >> part). See
A<sec:signatures> for more information.
The simplest way to sort the players by score would be C<@names.sort({
Expand All @@ -332,7 +332,7 @@ tournament.
When two array items have the same value, C<sort> leaves them in the same order
as it found them. Computer scientists call this a I<stable sort>. The program
takes advantage of this property of Perl 6's C<sort> to achieve the goal by
takes advantage of this property of Perl 6's C<sort> to achieve the goal by
sorting twice: first by the number of sets won (the secondary criterion), then
by the number of matches won.
Expand Down Expand Up @@ -382,7 +382,7 @@ not interpolate:
=end code
Double quoted strings in Perl 6 can interpolate variables with the C<$>
Double quoted strings in Perl 6 can interpolate variables with the C<$>
sigil as well as blocks of code in curly braces. Since any arbitrary
Perl code can appear within curly braces, C<Array>s and C<Hash>es may be
interpolated by placing them within curly braces.
Expand All @@ -394,12 +394,12 @@ item. Hashes within curly braces are interpolated as a series of
lines. Each line will contain a key, followed by a tab character, then
the value associated with that key, and finally a newline.
Let's see an example of this now.
Let's see an example of this now.
In this example, you will see some special syntax that makes it easier
to make a list of strings. This is the C<< <...> >> L<quote-words|https://docs.perl6.org/language/operators#index-entry-qw-quote-words-quote-words> construct.
When you put words in between the < and > they are all assumed to be strings,
so you do not need to wrap them each in double quotes C<< "..." >>.
so you do not need to wrap them each in double quotes C<< "..." >>.
=begin code
Expand Down Expand Up @@ -474,7 +474,7 @@ B<2.> Instead of deleting the redundant C<@names> variable, you can also use it
player appears that wasn't mentioned in the first line, for example due to a
typo. How would you modify your program to achieve that?
Hint: Try using L<membership operators|https://docs.perl6.org/routine/(elem)>.
Hint: Try using L<membership operators|https://docs.perl6.org/routine/(elem)>.
B<Answer:> Change C<@names> to C<@valid-players>. When looping through the lines of
the file, check to see that C<$p1> and C<$p2> are in C<@valid-players>. Note that
Expand Down

0 comments on commit bc7a753

Please sign in to comment.