文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>util perl - 时间差 ,读取配置文件, 过滤数据

util perl - 时间差 ,读取配置文件, 过滤数据

时间:2010-08-05  来源:liukaiyi





#at=2009-11-20 11:48:53<|>aip=122.....
# my %m = &getGMap;
# print $m{"asid"},"\t",$m{"at"},"\n" if not $m{"asid"} eq "" ;
sub getGMap{
 my @arr = split /<\|>/;
 my %h;
 foreach $d (@arr){
   if($d=~/(.*?)=(.*)/){
    $h{$1}=$2;
   }
 }
 return %h;
}

 
# perl -e '
# BEGIN{ require("/data/shell/gmodel/inc_model/utils.pl"); }
# print &diffTime("2009-12-04 16:58:38","2009-12-04 16:58:00");
# '
sub diffTime{
 use Time::Local;
 my($st1,$st2) = @_;
 my $t1=timelocal($6,$5,$4,$3,$2-1,$1-1900) if $st1=~/(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})/;
 my $t2=timelocal($6,$5,$4,$3,$2-1,$1-1900) if $st2=~/(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})/;
 return $t1-$t2;
}




# perl -e '
# BEGIN{ require("/data/shell/gmodel/inc_model/utils.pl"); }
# print &getAgoday(-3);
# #2009-12-31
# print &getAgoday(3);
# #...
# '
sub getAgoday{
 my $nt=$_[0];
 $nt = 1 if $nt !~ /(\-)*\d+/;
 $nt=`date -d "\$[$nt*-1] day" +%Y-%m-%d` if $nt ne "";
 chomp $nt;
 return $nt;
}
# print 23

sub getAgohour{
 my ($nt)=@_;
 $nt = 1 if $nt !~ /(\-)*\d+/;
 $nt=`date -d "\$[$nt*-1] hour" +%H`;
 chomp $nt;
 return $nt;
}


$_vtime=&getAgoday();
$_htime=&getAgohour();
sub setVTime{
 $_vtime=$_[0];
 $_htime=$_[1] if $_[1] ne "";
}



# perl -e '
# BEGIN{ require("/data/shell/gmodel/inc_model/utils.pl"); }
# # &setVTime('2010-11-12','23');
# print &getConf("logSou","audiobooks_logSou")
# '
use Config::Tiny;
$_Config=Config::Tiny->read("/data/shell/gmodel/inc_model/model.conf");
sub getConf{
 my ($_Y,$_M,$_D)=split /-/,$_vtime;
 my $_H = $_htime ;
 %rp = ("\@Y", $_Y,
       "\@M" , $_M,
       "\@D", $_D,
       "\@H", $_H );
 # 需要 cpan>install Config::Tiny
 my ($group,$key)=@_;
 my $ss=$_Config->{$group}->{$key};
 while (($key, $value) = each(%rp)){
    $ss=~s/$key/$value/g;
 }
 return $ss;
}


my $_filtered_ip=&getConf("filter","filtered_ip");
my @_filtered_ips=split(",", $_filtered_ip );
my $_filtered_aop=&getConf("filter","filtered_aop");
my @_filtered_aops=split(",", $_filtered_aop );
my $_permission_app=&getConf("filter","permission_app");
my @_permission_apps=split(",", $_permission_app );

sub my_filter{
 my %m=%{$_[0]};
 return 0 if $m{auid} eq "" or $m{ab} eq "";
 my @aip=split /,/,$m{aip};
 return 0 if(grep {$_ eq $m{aip} } @_filtered_ips);
 return 0 if(grep {$m{ab} eq $_} @_filtered_aops);
 
 if(not (grep {"ALL" eq $_} @_permission_apps) ){
  if (not (grep {$m{aop} eq $_} @_permission_apps)){
    return 0;
  }
 }
 return 1 ;
}

return 1;


相关阅读 更多 +
排行榜 更多 +
零界之痕手游安卓下载

零界之痕手游安卓下载

角色扮演 下载
漫游都市手机版下载

漫游都市手机版下载

赛车竞速 下载
涡轮螺旋桨飞行模拟器无限金币版下载

涡轮螺旋桨飞行模拟器无限金币版下载

模拟经营 下载