From 0de3c77ff03f11cff94be7f91ad134bcf9ffcb36 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Mon, 23 Nov 2020 15:04:44 +0100 Subject: Solution to task 1 --- challenge-088/jo-37/perl/ch-1.pl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 challenge-088/jo-37/perl/ch-1.pl diff --git a/challenge-088/jo-37/perl/ch-1.pl b/challenge-088/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..5225a6c847 --- /dev/null +++ b/challenge-088/jo-37/perl/ch-1.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl + +use Test2::V0; +use List::Util 'product'; + +sub prod_arr { + my $prod = product @_; + die "invalid data" unless $prod; + + map $prod / $_, @_ +} + +is [prod_arr 5, 2, 1, 4, 3], [24, 60, 120, 30, 40], 'Example 1'; +is [prod_arr 2, 1, 4, 3], [12, 24, 6, 8], 'Example 2'; +like dies {prod_arr 2, 1, 0}, qr/^invalid data/, + 'zero is not a positive integer'; +is [prod_arr 2, -5, 3], [-15, 6, -10], 'negative numbers are ok, though'; + +done_testing; -- cgit