Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Small and attractive Perl 6 snippets
my $birth-date-string = prompt "When were you born (yyyy-mm-dd)?";
my $birth-date = Date.new($birth-date-string);
my $today = Date.today;
my $age = $today.year - $birth-date.year;
# But your birthday this year may not have been yet
if $today.day-of-year < $birth-date.day-of-year {
$age--;
}
say "You are $age years old!";
my @scale = ("$_$_" for 0..9, <a b c d e f>);
my @zeroes = '00' xx 16;
# Fade from red to blue
for @scale.reverse Z @zeroes Z @scale -> $r, $g, $b {
say "#$r$g$b";
}
for 10 ... 0 -> $count {
say "$count...";
LAST { say "Liftoff!" };
}
my $sentence = "I am going to go feed the the cat.";
if $sentence ~~ / (\w+) \h+ $0 / {
say "Duplicate word '$0 $0' found at position $/.from().";
}
my @beers = 'beers', 'beer', 'beers' xx 97;
for reverse(1..99) Z reverse(0..98) -> $n, $nn {
say "$n @beers[$n] on the wall!";
say "$n @beers[$n]!";
say "Take one down, pass it around,";
say "$nn @beers[$nn] on the wall!";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.