Skip to content

Commit

Permalink
[basics] more minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Masak committed Nov 9, 2009
1 parent a8c0d89 commit 30057bc
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/basics.pod
Expand Up @@ -106,11 +106,11 @@ This list is stored into the array C<@names>.

Here two variables are declared as hashes. A C<Hash> is an unordered
collection of pairs of keys and values. Other programming languages call that
a I<hash table>, I<dictionary> or I<map>. You can ask a hash table for the
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}>.

Here in the score counting program C<%games> stores the number of won games
per player, and C<%sets> the number of won sets per player.
Here in the score counting program, C<%games> stores the number of won games
per player, and C<%sets> holds the number of won sets per player.

for $file.lines -> $line {
...
Expand Down Expand Up @@ -241,9 +241,9 @@ returns the increment value; C<my $x = 1; say ++$x> prints C<2>.

This might look a bit scary at first, but it consists of three relatively
simple steps. An array knows how to sort itself with the C<sort> method.
However to print out the winner first, we have to sort by the score of the
However, to print out the winner first, we have to sort by the score of the
player, not by its name. You can achieve that by passing a I<block> to the
sort method, which transforms the array elements (which are the names of
sort method, which transforms the array elements (the names of
players) to the thing you want to sort by. The array items are passed in
through the I<topic variable> C<$_>.

Expand All @@ -254,7 +254,7 @@ Perl 6 code, optionally with a signature (the C<< -> $line >> part).
More about that in the next chapter. (TODO: write that)

So the simplest way to sort the players by score would be
C<@names.sort({ %games{$_} })>, which sorts by number of won games. However
C<@names.sort({ %games{$_} })>, which sorts by number of won games. However,
Ana and Dave have both won two games, and that simple sort doesn't account for
the number of won sets, which is the secondary criterion to decide who has won
the tournament.
Expand All @@ -265,7 +265,7 @@ can use this fact to achieve our goal by two sorting twice: first sorting by
the number of won sets (the secondary criterion), then by the number of won
games.

After the first sorting step the names are in the order
After the first sorting step, the names are in the order
C<Beth Charlie Dave Ana>, and after the second sorting step it's again the
same, because nobody has won less games but more sets than somebody else
(which is quite possible, especially at larger tournaments).
Expand Down

0 comments on commit 30057bc

Please sign in to comment.