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