aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-062/yet-ebreo/perl/ch-1.pl43
1 files changed, 43 insertions, 0 deletions
diff --git a/challenge-062/yet-ebreo/perl/ch-1.pl b/challenge-062/yet-ebreo/perl/ch-1.pl
new file mode 100644
index 0000000000..097184fa3f
--- /dev/null
+++ b/challenge-062/yet-ebreo/perl/ch-1.pl
@@ -0,0 +1,43 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use feature 'say';
+use Getopt::Long 'GetOptions';
+
+my $unique;
+my @files;
+
+GetOptions(
+ 'unique' => \$unique,
+ "file=s{1,}" => \@files,
+);
+
+my %seen = ();
+sub sort_email {
+ chomp(my @data = @_);
+ for my $email ( sort { lc $a=~s/.*@//r cmp lc $b=~s/.*@//r or $a=~s/@.*//r cmp $b=~s/@.*//r } @data ) {
+ $email=~/@/;
+ $unique ? !$seen{$`.(lc $')} && say $email : say $email;
+ $seen{$`.lc $'}++;
+ }
+}
+my @emails;
+if (@files) {
+ for my $file (@files) {
+ if (-e $file) {
+ open my $handle, '<', $file;
+ push @emails, <$handle>;
+ close $handle;
+ }
+ }
+} else {
+ push @emails, <DATA>;
+}
+
+sort_email(@emails);
+__DATA__
+name@example.org
+rjt@cpan.org
+Name@example.org
+rjt@CPAN.org
+user@alpha.example.org \ No newline at end of file