diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-03-26 18:56:02 +0200 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-04-19 17:15:35 +0200 |
| commit | 3fec24b48245cef9ed4b99cc6d81703c40c16141 (patch) | |
| tree | 16eb2232e9167cec6534041189b12efba4463a57 /challenge-034 | |
| parent | 35201c7b6705a85b815ffc13a77f425ce70c97b7 (diff) | |
| download | perlweeklychallenge-club-3fec24b48245cef9ed4b99cc6d81703c40c16141.tar.gz perlweeklychallenge-club-3fec24b48245cef9ed4b99cc6d81703c40c16141.tar.bz2 perlweeklychallenge-club-3fec24b48245cef9ed4b99cc6d81703c40c16141.zip | |
Challenge 034 task 1
Diffstat (limited to 'challenge-034')
| -rwxr-xr-x | challenge-034/jo-37/perl/ch-1.pl | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-034/jo-37/perl/ch-1.pl b/challenge-034/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..b0ea0d66d8 --- /dev/null +++ b/challenge-034/jo-37/perl/ch-1.pl @@ -0,0 +1,32 @@ +#!/usr/bin/perl -s + +use v5.16; +use Test2::V0; +use warnings FATAL => 'all'; +use Data::Dump qw(dd pp); +use experimental qw(signatures postderef); +die <<EOS unless @ARGV == 2; +usage: $0 'A B C...' 'X Y Z...' + +'A B C...' 'X Y Z...' + two lists of words + +EOS + + +### Input and Output + +main: { + # Split arguments. + my @a = split /\s+/, shift; + my @b = split /\s+/, shift; + # Create "sets" %a and %b having the elements of @a and @b as keys + # *and* values. Using hash slices to populate the hashes. + my %a; + @a{@a} = @a; + my %b; + @b{@b} = @b; + # Build the intersection of %a and %b by using the %a's keys to + # slice %b. + say join ' ', grep defined, @b{keys %a}; +} |
