# HG changeset patch # User indvdum # Date 1308608922 -14400 # Node ID 7712f74efd6eb9e44403e2997cd2d2466ce575e1 # Parent b1e6dfadc2f8f40e397ff224eaf06e33af621ec2 * refactoring diff -r b1e6dfadc2f8 -r 7712f74efd6e email-filter.pl --- a/email-filter.pl Tue Jun 21 02:16:26 2011 +0400 +++ b/email-filter.pl Tue Jun 21 02:28:42 2011 +0400 @@ -7,42 +7,46 @@ 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; - illegalUse() if $excludeDomen ne '' && $arg !~ /--exclude-domen=\w*/; - $excludeDomen = shift() if $excludeDomen eq ''; - illegalUse() if $excludeDomen eq ''; +parseCommandLine(); +processFile(); +exit 0; + +# Парсер параметров командной строки +sub parseCommandLine { + my $arg = shift(@ARGV); + 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; + illegalUse() if $excludeDomen ne '' && $arg !~ /--exclude-domen=\w*/; + $excludeDomen = shift(@ARGV) if $excludeDomen eq ''; + illegalUse() if $excludeDomen eq ''; + } else { + illegalUse(); + } } else { - illegalUse(); + illegalUse() if $fileName ne ''; + $fileName = $arg; } - } else { - illegalUse() if $fileName ne ''; - $fileName = $arg; + $arg = shift(@ARGV); + }; + if (!$isHasArgs) { + about(); + exit 0; } - $arg = shift(); -}; -undef $arg; -if (!$isHasArgs) { - about(); - exit 0; } -processFile(); # Вывод информации о программе sub about {