Content deleted Content added
Mindmatrix (talk | contribs) update to Raku (programming language) |
Format code |
||
Line 219:
# cannot be predicted.
while (($name, $address) = each %addressbook) {
}
# Similar to the above, but sorted alphabetically
foreach my $next_name (sort keys %addressbook) {
}
</source>
Line 323:
<source lang="perl">
</source>
Line 339:
<source lang="perl">
sub function1 {
}
function1( x => 23 );
Line 369:
<source lang="perl">
sub either {
}
Line 452:
<source lang="perl">
sub Point::new {
# Here, Point->new(4, 5) will result in $class being 'Point'.
# It's a variable to support subclassing (see the perloop manpage).
my ($class, $x, $y) = @_;
bless [$x, $y], $class; # Implicit return
}
sub Point::distance {
my ($self, $from) = @_;
my ($dx, $dy) = ($$self[0] - $$from[0], $$self[1] - $$from[1]);
sqrt($dx * $dx + $dy * $dy);
}
</source>
|