multi sub MAIN($number, Bool :$upto) {
my @fib = 1, 1, *+* ... Inf;
if $upto {
say join ',', @fib[0 ..^ $number];
}
else {
say @fib[$number - 1];
}
}
multi sub MAIN(Str $name) { " " }
> perl6 MAIN.p6 10
55
> perl6 MAIN.p6 10 --upto
Usage:
MAIN.p6 [--upto] <number>
> perl6 MAIN.p6 --upto 10
1,1,2,3,5,8,13,21,34,55
)
multi sub MAIN(:$source, :$target, :$count, :$debug) {
say "source: $source" if $source.defined;
say "target: $target" if $target.defined;
say "count: $count" if $count.defined;
say "debug: $debug" if $debug.defined;
}
multi sub MAIN($source, $target, $count, $debug) {
say "source: $source";
say "target: $target";
say "count: $count";
say "debug: $debug";
}
constant @months = <January February March April May June July
August September October November December>;
constant @days = <Su Mo Tu We Th Fr Sa>;
sub center(Str $text, Int $width) {
my $prefix = ' ' x ($width - $text.chars) div 2;
my $suffix = ' ' x $width - $text.chars - $prefix.chars;
return $prefix ~ $text ~ $suffix;
}
multi sub MAIN(:$year = Date.today.year, :$month = Date.today.month) {
my $dt = Date.new(:year($year), :month($month), :day(1) );
my $ss = $dt.day-of-week % 7;
my @slots = ''.fmt("%2s") xx $ss;
my $days-in-month = $dt.days-in-month;
for $ss ..^ $ss + $days-in-month {
@slots[$_] = $dt.day.fmt("%2d");
$dt++
}
my $weekdays = @days.fmt("%2s").join: " ";
say center(@months[$month-1] ~ " " ~ $year, $weekdays.chars);
say $weekdays;
for @slots.kv -> $k, $v {
print "$v ";
print "\n" if ($k+1) %% 7 or $v == $days-in-month;
}
}
)
sub MAIN($file1, $file2) {
my $words1 = bag slurp($file1).comb(/\w+/).map(*.lc);
my $words2 = set slurp($file2).comb(/\w+/).map(*.lc);
my $unique = ($words1 (-) $words2);
for $unique.list.sort({ -$words1{$_} })[^10] -> $word {
say "$word: { $words1{$word} }";
}
}
sub MAIN( $string ){
my $p = run 'ps', 'auxww', :out;
my $header = $p.out.get;
say $header, '-' x 80;
for $p.out.lines {
next unless m/ $string /;
.trim;
my @v = .words;
next if @v[1] == $*PID;
.say;
}
say '-' x 80, $header;
}