From f98a47cf52857c61beaf1314ec315bd06ef31191 Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Thu, 26 Dec 2019 00:59:03 +0100 Subject: Add solution to 040 by E. Choroba --- challenge-040/e-choroba/perl5/ch-1.pl | 15 +++++++++++++++ challenge-040/e-choroba/perl5/ch-2.pl | 14 ++++++++++++++ 2 files changed, 29 insertions(+) create mode 100755 challenge-040/e-choroba/perl5/ch-1.pl create mode 100755 challenge-040/e-choroba/perl5/ch-2.pl diff --git a/challenge-040/e-choroba/perl5/ch-1.pl b/challenge-040/e-choroba/perl5/ch-1.pl new file mode 100755 index 0000000000..b24139aa16 --- /dev/null +++ b/challenge-040/e-choroba/perl5/ch-1.pl @@ -0,0 +1,15 @@ +#!/usr/bin/perl +use warnings; +use strict; +use feature qw{ say }; +use utf8; + +binmode *STDOUT, ':encoding(UTF-8)'; + +my @arrays = ([qw[ I L O V E Y O U ]], + [qw[ 2 4 0 3 2 0 1 9 ]], + [qw[ ! ? £ $ % ^ & * ]]); + +for my $i (0 .. $#{ $arrays[0] }) { + say join ' ', $i, map $_->[$i], @arrays; +} diff --git a/challenge-040/e-choroba/perl5/ch-2.pl b/challenge-040/e-choroba/perl5/ch-2.pl new file mode 100755 index 0000000000..baaf233c9a --- /dev/null +++ b/challenge-040/e-choroba/perl5/ch-2.pl @@ -0,0 +1,14 @@ +#!/usr/bin/perl +use warnings; +use strict; + +my @list = (10, 4, 1, 8, 12, 3); +my @indices = (0, 2, 5); + +my @sorted = @list; +@sorted[@indices] = sort { $a <=> $b } @sorted[@indices]; + +my @expected = (1, 4, 3, 8, 12, 10); + +"@sorted" eq "@expected" + or die "Got: @sorted\nExpected: @expected\n"; -- cgit