Skip to content

Instantly share code, notes, and snippets.

@masak
Created August 11, 2012 13:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masak/3324433 to your computer and use it in GitHub Desktop.
Save masak/3324433 to your computer and use it in GitHub Desktop.
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