- 论坛徽章:
- 0
|
第一个cgi文件调用了这个方法:
sub dispatch_search_tool{
my $self = shift;
my @index_word = $self->cgi->param('index_word'); #用来检索的文字列
my $charset_set = $self->cgi->param('charset_set'); #用来设置的字体编码
# 同じデータの入力チェック. 相同输入情况的检查
foreach my $item (@index_word){
my @same = grep { $item == $_ } @index_word;
my $flag;
# 入力不正処理. 不正确的处理
if(@same > 1){
$flag = 'err';
last;
# 入力正しい処理. 输入正确的处理
}else{
$flag = 'searching';
my $argv = join(' ', @index_word)." $charset_set";
system( "perl "."script.pl $argv"); }
}
}
script.pl文件:
#! /usr/local/bin/perl -w
use strict;
use UPS::String::Check;
use Jcode;
use UPS::DateTimeLite;
my @param = split(/ /, $ARGV[0]);
my $code = $ARGV[1];
#my @param = ('hoge');
#my $code = 'EUC_JP';
#my $jcode = Jcode->new('');
open(DATA,"<","/home/ssnw/perl-lib/SSNW/Waf/Contents/Tools/MailSearch/Conf.txt");
my @dir = <DATA>;
my $dir_log = shift @dir;
my $dir_result = shift @dir;
close(DATA);
$dir_log = $2 if($dir_log =~ /^(DIRECTORY_LOG)=(.*)$/);
$dir_result = $2 if($dir_result =~ /^(DIRECTORY_RESULT)=(.*)$/);
my $time = UPS::DateTimeLite->new->format('%Y%M%D%H%M%S');
my $temp;
my $flag = 1;
open(F,">>","/home/ssnw/tools/htdocs/grep_data/".$time.".txt");
foreach(@param){
if($_){
# $_ = $jcode->set($_,'sjis')->euc();
$_ =~s/\"/\\/g;
$_ = '"'.$_.'"';
if($flag){
$temp = "grep $_ /home/ssnw/tools/htdocs/grep_data/log.txt";
$flag = 0;
} else {
$temp .= " | grep $_";
}
print F "$_ ";
}
}
print F "\n";
close(F);
###############################
open(D,"<","/home/ssnw/tools/htdocs/grep_data/log.txt");
my @temp = <D>;
my $head = shift @temp;
my $end = pop @temp;
close(D);
open(A,">","/home/ssnw/tools/htdocs/grep_data/log.txt");
foreach(@temp){
print A "$_";
}
close(A);
###############################
my @record = qx($temp);
open(T,">","/home/ssnw/tools/htdocs/grep_data/log.txt");
print T "$head";
foreach(@temp){
print T "$_";
}
print T "$end";
close(T);
###############################
my @mail_contents;
my $cnt = 1;
my $strck = UPS::String::Check->new;
foreach(@record){
my ($date_time, $address, $subject, $msg) = split(/\t/,$_);
# DateTime
if ($date_time =~ /^(\[)(.*)(\])$/) {
if($strck->null($2)){
#print "DateTime is Empty at xxx.log line $cnt.\n";
}
$date_time = $2;
}
# Subject
if ($subject =~ /^(Subject):(.*)$/) {
if($strck->null($2)){
#print "$1 is Empty at xxx.log line $cnt.\n";
}
unless($strck->sjis($2)){
#print "perhaps $1 is EUC at xxx.log line $cnt.\n";
}
$subject = $2;
}
# Message
if ($msg =~ /^(Message):(.*)$/) {
if ($strck->null($2)){
#print "$1 is Empty at xxx.log line $cnt.\n";
}
unless($strck->sjis($2)){
#print "perhaps $1 is EUC at xxx.log line $cnt.\n";
}
$msg = $2;
}
$cnt++;
push(@mail_contents, $date_time."\t".$address."\t".$subject."\t".$msg."\n");
}
open(H,">>","/home/ssnw/tools/htdocs/grep_data/".$time.".txt");
foreach(@mail_contents){
print H "$_";
}
close(H);
#print "OK.\n";
请指教,谢谢!:em02::em02:
[ 本帖最后由 luol_001 于 2006-4-5 09:12 编辑 ] |
|