diff options
| -rwxr-xr-x | challenge-029/daniel-mita/perl6/ch-1.p6 | 19 | ||||
| -rwxr-xr-x | challenge-029/daniel-mita/perl6/ch-2.p6 | 15 |
2 files changed, 29 insertions, 5 deletions
diff --git a/challenge-029/daniel-mita/perl6/ch-1.p6 b/challenge-029/daniel-mita/perl6/ch-1.p6 new file mode 100755 index 0000000000..a3ab062c3d --- /dev/null +++ b/challenge-029/daniel-mita/perl6/ch-1.p6 @@ -0,0 +1,19 @@ +#!/usr/bin/env perl6 +use v6; + +#| Expand braces (nesting NYI) +sub MAIN ( + *@phrase where * > 0, + --> Nil +) { + given @phrase.join: ' ' -> $str { + given $str.match: /^ ( .*? ) '{' ( .* ) '}' ( .*? ) $/ { + when .[1].so { + for .[1].split: ',' -> $split { + "$_[0]$split$_[2]".say; + } + } + default { $str.say } + } + } +} diff --git a/challenge-029/daniel-mita/perl6/ch-2.p6 b/challenge-029/daniel-mita/perl6/ch-2.p6 index 9a6365be70..d5c144a5f0 100755 --- a/challenge-029/daniel-mita/perl6/ch-2.p6 +++ b/challenge-029/daniel-mita/perl6/ch-2.p6 @@ -2,21 +2,26 @@ use v6; use NativeCall; -sub getrandom ( Buf, size_t, uint32 --> ssize_t ) is native {*} +my %*SUB-MAIN-OPTS = + :named-anywhere, +; #| http://man7.org/linux/man-pages/man2/getrandom.2.html sub MAIN ( - UInt $bytes = 8, #= Number of random bytes (defaults to 8) - UInt $flags = 0, + UInt $bytes = 8, #= Number of random bytes (defaults to 8) + UInt :$flags = 0, + --> Nil ) { - given Buf.allocate($bytes) { + given Buf.allocate: $bytes { given .&getrandom: $bytes, $flags { when -1 { die sub strerror( int32 --> Str ) is native {*}( - cglobal( ('c', v6), 'errno', int32 ) ); + cglobal |( 'c', v6; 'errno'; int32 ) ); } when * < $bytes { die 'got fewer bytes than requested' } } .say; } } + +sub getrandom ( Buf, size_t, uint32 --> ssize_t ) is native {*} |
