From 5b0ef14b12c3e54783b8968977c33911b04e67d7 Mon Sep 17 00:00:00 2001 From: Ysmael Ebreo Date: Tue, 26 May 2020 00:13:13 +0800 Subject: Added perl solution ch#62-1 --- challenge-062/yet-ebreo/perl/ch-1.pl | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 challenge-062/yet-ebreo/perl/ch-1.pl 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, ; +} + +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 -- cgit