Returns nothing.
Checks the magical lexical (S02) $?OS against a junction consisting of 3 values. Use the ternary operator ?? :: to decide what system command to use to clear the screen.
$?OS
?? ::
err is the low precedence form of // (S03). // is especially useful in its assignment form:
err
//
$x //= $y;
To summarize, || and or relate to truth, while // and err relate to definedness.
||
or
Next, we use smart matching, ~~, to skip all of the lines from the beginning of the file which have something other than whitespace.
~~
In the loop that follows:
for (=$dict) -> $name {
we use the unary = to perform a readline operation on the filehandle.
=
readline
We look over the numbers which are the indices to the elements of the array @letters by forcing the array into numerical context:
@letters
for (0 .. (+@letters - 1)) -> $i {
Now, ~= might throw you. You Perl 5'ers are seeing the regexp matching operator in reverse. But what you should be seeing is the Perl 6 string concatenation operator (~) followed by an equal sign. Which therefore means that
~=
~
$output ~= @letters[$i];
translates to:
$output = $output ~ @letters[$i] ;
In the grep here:
grep
@letters == @solution.grep:{ $_ ne '' };
the block beginning with a colon is called an adverbial block. It is equivalent with:
grep(@solutions: { $_ ne '' })
In both cases, @solutions is the invocant, and the block is the argument.
@solutions
The loop construction (S04) is used without the the statement modifiers until or <while> which it can take.
until
sub draw_if_greater_than (Str $char, Int $num) returns Bool { ($number_of_bad_guesses >= $num) ?? $char :: ' '; }
The character for blank should be a constant, e.g.:
my ($BLANK) is constant = ' ';
but it is not implemented yet.
Here we see function interpolation, i.e. the use of { ... } blocks inside strings.
{ ... }
Note that the list-context x in Perl 5 is now xx in Perl 6:
x
xx
@solution = ('' xx +@letters);
If you read Apocalypse 03, you will see strong motivation for changing the ternary operator syntax.
Terrence "metaperl" Brannon
Substantial #perl6 help from
mauke, ninereaons, revdiablo, autrijus, stevan
To install Perl6::Pugs, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perl6::Pugs
CPAN shell
perl -MCPAN -e shell install Perl6::Pugs
For more information on module installation, please visit the detailed CPAN module installation guide.