From 391cdbc32dda7fc76b2bcc3d88b6d2cf073be254 Mon Sep 17 00:00:00 2001 From: Joelle Maslak Date: Sat, 12 Oct 2019 20:28:37 -0600 Subject: Joelle's solutions for 29.2 in Perl 5 & Perl 6 --- challenge-029/joelle-maslak/perl5/ch-2.pl | 21 +++++++++++++++++++++ challenge-029/joelle-maslak/perl6/ch-2.p6 | 15 +++++++++++++++ 2 files changed, 36 insertions(+) create mode 100755 challenge-029/joelle-maslak/perl5/ch-2.pl create mode 100755 challenge-029/joelle-maslak/perl6/ch-2.p6 diff --git a/challenge-029/joelle-maslak/perl5/ch-2.pl b/challenge-029/joelle-maslak/perl5/ch-2.pl new file mode 100755 index 0000000000..a568fa97cf --- /dev/null +++ b/challenge-029/joelle-maslak/perl5/ch-2.pl @@ -0,0 +1,21 @@ +#!/usr/bin/env perl +use v5.22; +use strict; +use warnings; + +use Inline 'C'; + +MAIN: { + say "15! = " . factorial(15); +} + +__END__ +__C__ + +long factorial(long x) { + if (x < 0) { return -1; } + if (x < 1) { return 1; } + + return x * factorial(x-1); +} + diff --git a/challenge-029/joelle-maslak/perl6/ch-2.p6 b/challenge-029/joelle-maslak/perl6/ch-2.p6 new file mode 100755 index 0000000000..c5b7dd2864 --- /dev/null +++ b/challenge-029/joelle-maslak/perl6/ch-2.p6 @@ -0,0 +1,15 @@ +#!/usr/bin/env perl6 +use v6; + +use NativeCall; + +sub MAIN(UInt:D $seconds = 2) { + my $ret = native-sleep($seconds); + say "Sleep returned a value of $ret"; +} + +# This will fail on 32 bit environments, you can't use "uint" for types +# unfortunately. But if someone knows a workaround so you don't have to +# specify length (just use native C lengths), I'd love to hear that. +my sub native-sleep(uint64 -->uint64) is native is symbol('sleep') { * } + -- cgit