diff -r ba47eb1a50b4 -r 460bc4e6539f email-filter.pl --- a/email-filter.pl Mon Jun 20 18:33:06 2011 +0400 +++ b/email-filter.pl Tue Jun 21 02:02:08 2011 +0400 @@ -1,6 +1,51 @@ #!/usr/bin/perl +use strict; -$about = q { +# Глобальные переменные +my $fileName; +my $isRemoveDuplicates = 0; +my $isSplitByDomens = 0; +my $excludeDomen; + +# Парсим параметры командной строки +my $arg = shift(); +my $isHasArgs = 0; +until ($arg eq '') { + $isHasArgs = 1; + if($arg =~ /^-{1,2}.+$/){ + if ($arg =~ /^-{1,2}version$/){ + about(); + exit 0; + } elsif ($arg =~ /^-{1,2}help$/){ + help(); + exit 0; + } elsif ($arg eq '--remove-duplicates'){ + $isRemoveDuplicates = 1; + } elsif ($arg eq '--split-by-domens'){ + $isSplitByDomens = 1; + } elsif ($arg =~ /--exclude-domen[=]{0,1}(\w*)/){ + $excludeDomen = $1; + $excludeDomen = shift() if $excludeDomen eq ''; + illegalUse() if $excludeDomen eq ''; + } else { + illegalUse(); + } + } else { + illegalUse() if $fileName ne ''; + $fileName = $arg; + } + $arg = shift(); +}; +undef $arg; +if (!$isHasArgs) { + about(); + exit 0; +} +processFile(); + +# Вывод информации о программе +sub about { + my $about = q { E-mail filter tool for Aptech version 0.1 @@ -8,5 +53,37 @@ This program may be used under Apache License 2.0. }; + + print $about; +} -print $about; \ No newline at end of file +# Вывод доступных параметров командной строки +sub help { + my $help = q {usage: }.$0. q { [KEYS] FILENAME [KEYS] + +Parse for e-mails file FILENAME with arguments KEYS and print result to standart output stream. + +Arguments: + --help print this help + --version print version and information about this script + --remove-duplicates remove e-mail duplicates + --split-by-domens split e-mails by domens + --exclude-domen[=]DOMEN exclude e-mails with domen DOMEN +}; + print $help; +} + +# Неправильный формат параметров командной строки +sub illegalUse { + print "Illegal use!\n\n"; + help(); + exit 1; +} + +# Обработка файла +sub processFile { + print "fileName = $fileName\n"; + print "isRemoveDuplicates = $isRemoveDuplicates\n"; + print "isSplitByDomens = $isSplitByDomens\n"; + print "excludeDomen = $excludeDomen\n"; +} \ No newline at end of file