Skip to content

Commit

Permalink
Merge branch 'master' of github.com:perl6/book
Browse files Browse the repository at this point in the history
  • Loading branch information
perlpilot committed Nov 16, 2009
2 parents 64430cd + f79f96f commit 043c4c7
Show file tree
Hide file tree
Showing 4 changed files with 387 additions and 28 deletions.
26 changes: 26 additions & 0 deletions bin/ascii-to-pod.pl
@@ -0,0 +1,26 @@
use strict;
use warnings;
use 5.010;
use utf8;
use open IO => ':encoding(utf8)';;

use Data::Dumper;
$Data::Dumper::Useqq = 1;

say "=begin table\n";
while (<>) {
chomp;
s/^\s+//;
next unless length $_;
my @row = split /\s{2,}/, $_;
say "=headrow\n" if $. == 1;
say "=row\n";
for my $c (@row) {
say "=cell $c\n";
}
say "=bodyrows\n" if $. == 1;
}
say "=end table";
6 changes: 4 additions & 2 deletions docs/TODO
@@ -1,14 +1,16 @@
This is a list of *technical* TODO items that needs to be solved

* non-ASCII-Characters (notably « and ») are silently missing from the PDF
* investigate syntax highlighting or emphasizing for the code examples
* investigate how to do proper cross-references
* code blocks preserve all leading whitespaces, leading to indented code
examples - that should not be the case, or at maybe be optional
examples - that should not be the case, or at least be optional
* maybe we need a more elaborate Makefile when we get more images
* C<^> is rendered as ^{}, see http://rt.cpan.org/Public/Bug/Display.html?id=50794

RESOLVED
* footnotes produce some Mojibake
- it seems that Pod::PseudoPod only wants single angle brackets on N<...>,
N<< ... >> adds some additional angle brackets to the TeX output.
* investigate syntax highlighting or emphasizing for the code examples
- inside of =begin programlisting ... =end programlisting, B<...> works
for emphasizing.
64 changes: 64 additions & 0 deletions src/basics.pod
Expand Up @@ -106,6 +106,11 @@ I'm not clear about the intent of the following paragraph. It starts to
explain scalars, but then veers off into "arbitrary values", which could mean a
lot of things.

Scalar variables B<can> hold anything you can store in variables, including
Arrays and Hashes. How should I write that instead? Would "Variables starting
with a dollar are the most permissive, and can hold an arbitrary object" be
better? --moritz

=end for

X<files; handle>
Expand Down Expand Up @@ -424,4 +429,63 @@ C<"...">. Single quoted strings C<'...> do not interpolate:
TODO: explain (non-)interpolation of arrays and hashes once Rakudo gets that
right

=head1 Exercises

B<1.> The input format of the example program is redundant: the first line
containing the name of all players is not necessary, because you can find out
which players participated in the tournament simply by looking at their names
in the subsequent rows.

How can you change the program if the first input line is omitted?
Hint: C<%hash.keys> returns a list of all keys stored in C<%hash>.

B<Answer:> Remove the line C<my @names = $file.get.split(' ');>, and change

=begin programlisting

my @sorted = @names.sort({ %sets{$_} }).sort({ %games{$_} }).reverse;

=end programlisting

into

=begin programlisting

my @sorted = B<%sets.keys>.sort({ %sets{$_} }).sort({ %games{$_} }).reverse;

=end programlisting


B<2.> Instead of removing the redundancy, you can also use it to warn if a
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?

B<Answer:> introduce another hash with the names of the legitimate players as
keys, and look in this hash when the name of a player is read:

=begin programlisting

...
my @names = $file.get.split(' ');
B<my %legitimate-players>
B<for @names -> $n {>
B< %legitimate-players{$n} = 1;>
B<}>

...

for $file.lines -> $line {
my ($pairing, $result) = $line.split(' | ');
my ($p1, $p2) = $pairing.split(' vs ');
B<for $p1, $p2 -> $p {>
B< if !%legitimate-players{$p} {>
B< say "Warning: '$p' is not on our list!";>
B< }>
B<}>

...
}

=end programlisting

=for vim: spell

0 comments on commit 043c4c7

Please sign in to comment.