aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Miner <simon.miner@gmail.com>2020-05-25 16:58:10 -0400
committerSimon Miner <simon.miner@gmail.com>2020-05-25 16:58:10 -0400
commit653cb05ccd2c99ab4c77e0f700fc7aeddb03bb8f (patch)
tree7586864b029f2dfe724ee2f74a709ba9c56507a2
parentc15f69e800292020dc94c7ee60a6c9be85eec854 (diff)
downloadperlweeklychallenge-club-653cb05ccd2c99ab4c77e0f700fc7aeddb03bb8f.tar.gz
perlweeklychallenge-club-653cb05ccd2c99ab4c77e0f700fc7aeddb03bb8f.tar.bz2
perlweeklychallenge-club-653cb05ccd2c99ab4c77e0f700fc7aeddb03bb8f.zip
Add -u CLI flag to print unique sorted emails
-rw-r--r--challenge-062/simon-miner/perl/ch-1.pl10
1 files changed, 10 insertions, 0 deletions
diff --git a/challenge-062/simon-miner/perl/ch-1.pl b/challenge-062/simon-miner/perl/ch-1.pl
index eadfcd1b17..6cce429f77 100644
--- a/challenge-062/simon-miner/perl/ch-1.pl
+++ b/challenge-062/simon-miner/perl/ch-1.pl
@@ -2,12 +2,22 @@
use strict;
use warnings;
+use Getopt::Std;
+
+my %args = ();
+getopts( 'u', \%args );
my %domains = ();
+my %seen = ();
while ( <> ) {
chomp;
my ( $mailbox, $domain ) = split( m/\@/ );
+
+ my $normalized = $mailbox . '@' . lc( $domain );
+ next if $args{u} && exists( $seen{$normalized} );
+
push( @{ $domains{$domain} }, $mailbox );
+ $seen{$normalized} = 1;
}
my @sorted = ();