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