email-filter.pl
author indvdum
Tue, 21 Jun 2011 02:28:42 +0400
changeset 5 7712f74efd6e
parent 4 b1e6dfadc2f8
child 6 37eab168f50c
permissions -rwxr-xr-x
* refactoring
     1 #!/usr/bin/perl
     2 use strict;
     3 
     4 # Глобальные переменные
     5 my $fileName;
     6 my $isRemoveDuplicates = 0;
     7 my $isSplitByDomens = 0;
     8 my $excludeDomen;
     9 
    10 parseCommandLine();
    11 processFile();
    12 exit 0;
    13 
    14 # Парсер параметров командной строки
    15 sub parseCommandLine {
    16 	my $arg = shift(@ARGV);
    17 	my $isHasArgs = 0;
    18 	until ($arg eq '') {
    19 		$isHasArgs = 1;
    20 		if($arg =~ /^-{1,2}.+$/){
    21 			if ($arg =~ /^-{1,2}version$/){
    22 				about();
    23 				exit 0;
    24 			} elsif ($arg =~ /^-{1,2}help$/){
    25 				help();
    26 				exit 0;
    27 			} elsif ($arg eq '--remove-duplicates'){
    28 				$isRemoveDuplicates = 1;
    29 			} elsif ($arg eq '--split-by-domens'){
    30 				$isSplitByDomens = 1;
    31 			} elsif ($arg =~ /--exclude-domen[=]{0,1}(\w*)/){
    32 				$excludeDomen = $1;
    33 				illegalUse() if $excludeDomen ne '' && $arg !~ /--exclude-domen=\w*/;
    34 				$excludeDomen = shift(@ARGV) if $excludeDomen eq '';
    35 				illegalUse() if $excludeDomen eq '';
    36 			} else {
    37 				illegalUse();
    38 			}
    39 		} else {
    40 			illegalUse() if $fileName ne '';
    41 			$fileName = $arg;
    42 		}
    43 		$arg = shift(@ARGV);
    44 	};
    45 	if (!$isHasArgs) {
    46 		about();
    47 		exit 0;
    48 	}
    49 }
    50 
    51 # Вывод информации о программе
    52 sub about {
    53 	my $about = q {
    54 E-mail filter tool for Aptech
    55 version 0.1
    56 
    57 Copyright 2011, David Veliev (gotoindvdum@gmail.com).
    58 
    59 This program may be used under Apache License 2.0.
    60 };
    61 	
    62 	print $about;
    63 }
    64 
    65 # Вывод доступных параметров командной строки
    66 sub help {
    67 	my $help = q {usage: }.$0. q { [KEYS] FILENAME [KEYS]
    68 
    69 Parse for e-mails file FILENAME with arguments KEYS and print result to standart output stream.
    70 
    71 Arguments:
    72     --help                      print this help
    73     --version                   print version and information about this script
    74     --remove-duplicates         remove e-mail duplicates
    75     --split-by-domens           split e-mails by domens
    76     --exclude-domen[=]DOMEN     exclude e-mails with domen DOMEN
    77 };
    78 	print $help;
    79 }
    80 
    81 # Неправильный формат параметров командной строки
    82 sub illegalUse {
    83 	print "Illegal use!\n\n";
    84 	help();
    85 	exit 1;	
    86 }
    87 
    88 # Обработка файла
    89 sub processFile {
    90 	print "fileName = $fileName\n";
    91 	print "isRemoveDuplicates = $isRemoveDuplicates\n";
    92 	print "isSplitByDomens = $isSplitByDomens\n";
    93 	print "excludeDomen = $excludeDomen\n";
    94 }