1.1 --- a/email-filter.pl Mon Jun 20 18:33:06 2011 +0400
1.2 +++ b/email-filter.pl Tue Jun 21 02:02:08 2011 +0400
1.3 @@ -1,6 +1,51 @@
1.4 #!/usr/bin/perl
1.5 +use strict;
1.6
1.7 -$about = q {
1.8 +# Глобальные переменные
1.9 +my $fileName;
1.10 +my $isRemoveDuplicates = 0;
1.11 +my $isSplitByDomens = 0;
1.12 +my $excludeDomen;
1.13 +
1.14 +# Парсим параметры командной строки
1.15 +my $arg = shift();
1.16 +my $isHasArgs = 0;
1.17 +until ($arg eq '') {
1.18 + $isHasArgs = 1;
1.19 + if($arg =~ /^-{1,2}.+$/){
1.20 + if ($arg =~ /^-{1,2}version$/){
1.21 + about();
1.22 + exit 0;
1.23 + } elsif ($arg =~ /^-{1,2}help$/){
1.24 + help();
1.25 + exit 0;
1.26 + } elsif ($arg eq '--remove-duplicates'){
1.27 + $isRemoveDuplicates = 1;
1.28 + } elsif ($arg eq '--split-by-domens'){
1.29 + $isSplitByDomens = 1;
1.30 + } elsif ($arg =~ /--exclude-domen[=]{0,1}(\w*)/){
1.31 + $excludeDomen = $1;
1.32 + $excludeDomen = shift() if $excludeDomen eq '';
1.33 + illegalUse() if $excludeDomen eq '';
1.34 + } else {
1.35 + illegalUse();
1.36 + }
1.37 + } else {
1.38 + illegalUse() if $fileName ne '';
1.39 + $fileName = $arg;
1.40 + }
1.41 + $arg = shift();
1.42 +};
1.43 +undef $arg;
1.44 +if (!$isHasArgs) {
1.45 + about();
1.46 + exit 0;
1.47 +}
1.48 +processFile();
1.49 +
1.50 +# Вывод информации о программе
1.51 +sub about {
1.52 + my $about = q {
1.53 E-mail filter tool for Aptech
1.54 version 0.1
1.55
1.56 @@ -8,5 +53,37 @@
1.57
1.58 This program may be used under Apache License 2.0.
1.59 };
1.60 +
1.61 + print $about;
1.62 +}
1.63
1.64 -print $about;
1.65 \ No newline at end of file
1.66 +# Вывод доступных параметров командной строки
1.67 +sub help {
1.68 + my $help = q {usage: }.$0. q { [KEYS] FILENAME [KEYS]
1.69 +
1.70 +Parse for e-mails file FILENAME with arguments KEYS and print result to standart output stream.
1.71 +
1.72 +Arguments:
1.73 + --help print this help
1.74 + --version print version and information about this script
1.75 + --remove-duplicates remove e-mail duplicates
1.76 + --split-by-domens split e-mails by domens
1.77 + --exclude-domen[=]DOMEN exclude e-mails with domen DOMEN
1.78 +};
1.79 + print $help;
1.80 +}
1.81 +
1.82 +# Неправильный формат параметров командной строки
1.83 +sub illegalUse {
1.84 + print "Illegal use!\n\n";
1.85 + help();
1.86 + exit 1;
1.87 +}
1.88 +
1.89 +# Обработка файла
1.90 +sub processFile {
1.91 + print "fileName = $fileName\n";
1.92 + print "isRemoveDuplicates = $isRemoveDuplicates\n";
1.93 + print "isSplitByDomens = $isSplitByDomens\n";
1.94 + print "excludeDomen = $excludeDomen\n";
1.95 +}
1.96 \ No newline at end of file