diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-05-25 18:22:57 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-25 18:22:57 +0100 |
| commit | 50c6328f38c8b775c0bf62fae730586552b672cd (patch) | |
| tree | 8afaf28815cd178358c351983c58af81a0224879 | |
| parent | 32397cd7396185b9eaf93c8a453f6f3138c4461e (diff) | |
| parent | 5b0ef14b12c3e54783b8968977c33911b04e67d7 (diff) | |
| download | perlweeklychallenge-club-50c6328f38c8b775c0bf62fae730586552b672cd.tar.gz perlweeklychallenge-club-50c6328f38c8b775c0bf62fae730586552b672cd.tar.bz2 perlweeklychallenge-club-50c6328f38c8b775c0bf62fae730586552b672cd.zip | |
Merge pull request #1760 from Doomtrain14/master
Added perl solution ch#62-1
| -rw-r--r-- | challenge-062/yet-ebreo/perl/ch-1.pl | 43 |
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 |
