diff options
| author | Niels van Dijke <perlboy@cpan.org> | 2020-05-25 08:15:18 +0000 |
|---|---|---|
| committer | Niels van Dijke <perlboy@cpan.org> | 2020-05-25 08:15:18 +0000 |
| commit | b5cb68e61e73b1e9791f8e8f0f30d58ae9aeae28 (patch) | |
| tree | 4839cef4254ed101fc4d2d8d630a40ba4de7929a /challenge-062 | |
| parent | 3a5332d7b344d554f481faa1da1486880d959fbc (diff) | |
| download | perlweeklychallenge-club-b5cb68e61e73b1e9791f8e8f0f30d58ae9aeae28.tar.gz perlweeklychallenge-club-b5cb68e61e73b1e9791f8e8f0f30d58ae9aeae28.tar.bz2 perlweeklychallenge-club-b5cb68e61e73b1e9791f8e8f0f30d58ae9aeae28.zip | |
Task #1
Diffstat (limited to 'challenge-062')
| -rw-r--r-- | challenge-062/perlboy1967/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-062/perlboy1967/perl/ch-1.pl | 42 |
2 files changed, 43 insertions, 0 deletions
diff --git a/challenge-062/perlboy1967/blog.txt b/challenge-062/perlboy1967/blog.txt new file mode 100644 index 0000000000..b8d62bb7bb --- /dev/null +++ b/challenge-062/perlboy1967/blog.txt @@ -0,0 +1 @@ +URL to the blog diff --git a/challenge-062/perlboy1967/perl/ch-1.pl b/challenge-062/perlboy1967/perl/ch-1.pl new file mode 100755 index 0000000000..aba014f6f6 --- /dev/null +++ b/challenge-062/perlboy1967/perl/ch-1.pl @@ -0,0 +1,42 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +my @emailInput; +my @emailOutput; + +# Prototype for 'by reference' variables (speed) +sub sortEmail ($$); + +my $uniq = (($ARGV[0] // '') eq '-u' ? 1 : 0); +shift(@ARGV) if $uniq; +push(@ARGV, '-') unless @ARGV; + +foreach (@ARGV) { + my $fh; + + if ($_ eq '-') { + open($fh, '<&STDIN'); + } else { + open($fh, $_); + } + + while (<$fh>) { + push (@emailInput, $1) if (m#^\s*(.*?)\s*$#); + } +} + +@emailOutput = sort sortEmail @emailInput; +@emailOutput = keys { map { lc($_) => 1 } @emailOutput} + if ($uniq); + +print join("\n", @emailOutput, ''); + +sub sortEmail ($$) { + my ($r1, $d1) = $_[0] =~ m#^([^@]+)@(.*)#; + my ($r2, $d2) = $_[1] =~ m#^([^@]+)@(.*)#; + + return (lc($d1) cmp lc($d2) || $r1 cmp $r2); +} + |
