From 17215128f038bcdf444e5a0936df8ee9b8acd42d Mon Sep 17 00:00:00 2001 From: drudge Date: Thu, 23 Nov 2023 08:26:32 -0800 Subject: [PATCH] ch4 done --- ch4/ex4-5.raku | 14 ++++++++++++++ ch4/ex4-6.raku | 5 +++++ ch4/ex4-7.raku | 10 ++++++++++ 3 files changed, 29 insertions(+) create mode 100644 ch4/ex4-5.raku create mode 100644 ch4/ex4-6.raku create mode 100644 ch4/ex4-7.raku diff --git a/ch4/ex4-5.raku b/ch4/ex4-5.raku new file mode 100644 index 0000000..cb695ac --- /dev/null +++ b/ch4/ex4-5.raku @@ -0,0 +1,14 @@ +sub MAIN ( + $num1, #= Number to perform arithmatic on + $num2 #= Second number to perform arithmatic on +) { + die "unexpected input" unless is-numeric($num1) and is-numeric($num2); + say "sum is {$num1 + $num2}"; + say "difference is {$num1 - $num2}"; + say "product is {$num1 * $num2}"; + say "quotient is {$num1 / $num2}"; +} + +sub is-numeric ($num) { + return val($num) ~~ Numeric; +} diff --git a/ch4/ex4-6.raku b/ch4/ex4-6.raku new file mode 100644 index 0000000..bca02b6 --- /dev/null +++ b/ch4/ex4-6.raku @@ -0,0 +1,5 @@ +sub MAIN ( + $my-string #= String to count characters/display +) { + say "$my-string has {$my-string.chars} characters"; +} diff --git a/ch4/ex4-7.raku b/ch4/ex4-7.raku new file mode 100644 index 0000000..4708bf2 --- /dev/null +++ b/ch4/ex4-7.raku @@ -0,0 +1,10 @@ +sub MAIN () { + # Unset PATH for shell safety (pg. 68) + %*ENV = ''; + print Q :x 'C:\Windows\System32\hostname.exe' if $*DISTRO.is-win; + print Q :x '/bin/hostname' unless $*DISTRO.is-win; + + #avoid variable inputs for shell scripts + #qqx/date $my-new-date/ + #my $my-new-date = '; /bin/rm -rf'; +}