Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当要求计数时,Perl挂起++_Perl - Fatal编程技术网

当要求计数时,Perl挂起++

当要求计数时,Perl挂起++,perl,Perl,我正在写一段代码,从日志中提取一些信息。 但每次运行时,Perl都会挂起,文本文件的大小也不会增加 #!/usr/bin/perl print "What are the month of logs you're looking to start?\n"; $opt1 = <>; chomp($opt1); print "What are the month of logs you're looking to end search?\n"; $opt2 = <>; cho

我正在写一段代码,从日志中提取一些信息。 但每次运行时,Perl都会挂起,文本文件的大小也不会增加

#!/usr/bin/perl
print "What are the month of logs you're looking to start?\n";
$opt1 = <>;
chomp($opt1);
print "What are the month of logs you're looking to end search?\n";
$opt2 = <>;
chomp($opt2);
print "What are the day of logs you're looking to start?\n";
$opt3 = <>;
chomp($opt3);
print "What are the day of logs you're looking to end search?\n";
$opt4 = <>;
chomp($opt4);

for($month=$opt1;$month<$opt2;$month++) 
{
my $mymonth = sprintf '%02d', $month;

for($myDay=$opt3;$myDay<$opt4;$myDay++)
{
my $myDay2 = sprintf '%02d', $myDay;

#---------------------------------------------------------
# SET YESTERDAY DATE
# ----------------------
my $now = defined $_[0] ? $_[0] : time;
my $then = $now - 60*60*24*$myDay;
my $ndst = (localtime $now)[8] > 0;
my $tdst = (localtime $then)[8] > 0;

$then - ($tdst - $ndst) * 60 * 60 ;

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($then);
my $yesterday ="16".$mymonth.$myDay2;
my $today =$yesterday;
print $today."\n";

my $count100 = 0;
my $count200 = 0;
my $count500 = 0;


print "\nCount total charging 200, 500 DN".$today.".log\n";
open (textfile,"C:\\VasBoss\\Log\\didi\\DN".$today.".log");

open (MYFILE, ">> 2TK.txt");
open (MYFILE2, ">> 5TK.txt");
open (MYFILE3, ">> 1TK.txt");

while (<textfile>)
{
($MobileNo,$SubscriberID,$Shortcode,$Telco,$MO_time,$MO_id,$TransactionType,$Language,$Content,$checkprice,$ChargeStatus,$Contentmsg,$ChatDisabled)= split(/,/);
($date,$MobileNo1)  = split(/\>/,$MobileNo);
($MobileNo2,$MobileNo3)  = split(/\=/,$MobileNo1);
($Content1,$Content2)  = split(/\>/,$Content);
if(($checkprice =~ /200$/i ) && ($Content2 =~ /=0$/i))
{       
    print MYFILE $MobileNo3."\n";
    $count200++;

}
if(($checkprice =~ /500$/i ) && ($Content2 =~ /=0$/i))
{       
    print MYFILE2 $MobileNo3."\n";
    $count500++;
}

if(($checkprice =~ /100$/i ) && ($Content2 =~ /=0$/i))
{       
    print MYFILE3 $MobileNo3."\n";
    $count100++;
}
}
print $count100;
print $count200;
print $count500;
sleep;
}
}
编辑,我找到了解决方案。
我发现全局显式变量与我的编译冲突。

我认为您的问题在于:

sleep;  
因为从

使脚本休眠整数EXPR秒,如果未提供参数,则永久休眠

但是,当我们这样做的时候:

使用严格的警告和警告 3使用词法文件句柄打开参数是更好的样式。 从open检查您的退货代码。 这就是解决办法。 我替换变量my count100=0;计数100=0;然后它起作用了,它给出了我想要的结果

#!/usr/bin/perl

use warnings;

print "What are the month of logs you're looking to start?\n";
my $opt1 = <>;
chomp($opt1);
print "What are the month of logs you're looking to end search?\n";
my $opt2 = <>;
chomp($opt2);
print "What are the day of logs you're looking to start?\n";
my $opt3 = <>;
chomp($opt3);
print "What are the day of logs you're looking to end search?\n";
my $opt4 = <>;
chomp($opt4);

for($month=$opt1;$month<$opt2;$month++) 
{
    my $mymonth = sprintf '%02d', $month;

for($myDay=$opt3;$myDay<$opt4;$myDay++)
{
    my $myDay2 = sprintf '%02d', $myDay;

#---------------------------------------------------------
# SET YESTERDAY DATE
# ----------------------
my $now = defined $_[0] ? $_[0] : time;
my $then = $now - 60*60*24*$myDay;
my $ndst = (localtime $now)[8] > 0;
my $tdst = (localtime $then)[8] > 0;

$then - ($tdst - $ndst) * 60 * 60 ;

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($then);
my $yesterday ="16".$mymonth.$myDay2;
my $today =$yesterday;
print $today."\n";

$count100 = 0;
$count200 = 0;
$count500 = 0;


print "\nCount total charging 200, 500 DN".$today.".log\n";
open (textfile,"C:\\VasBoss\\Log\\didi\\DN".$today.".log");

open (MYFILE, ">> 2TK.txt");
open (MYFILE2, ">> 5TK.txt");
open (MYFILE3, ">> 1TK.txt");

while (<textfile>)
{
    ($MobileNo,$SubscriberID,$Shortcode,$Telco,$MO_time,$MO_id,$TransactionType,$Language,$Content,$checkprice,$ChargeStatus,$Contentmsg,$ChatDisabled)= split(/,/);
    ($date,$MobileNo1)  = split(/\>/,$MobileNo);
    ($MobileNo2,$MobileNo3)  = split(/\=/,$MobileNo1);
    ($Content1,$Content2)  = split(/\>/,$Content);
    if(($checkprice =~ /200$/i ) && ($Content2 =~ /=0$/i))
    {       
        print MYFILE $MobileNo3."\n";
         $count200++;

    }
    if(($checkprice =~ /500$/i ) && ($Content2 =~ /=0$/i))
    {       
        print MYFILE2 $MobileNo3."\n";
         $count500++;
    }

    if(($checkprice =~ /100$/i ) && ($Content2 =~ /=0$/i))
    {       
        print MYFILE3 $MobileNo3."\n";
        $count100++;
    }
}

}

}

print $count100."\n";
print $count200."\n";
print $count500."\n";
但您可能打算打印一个换行符,因此您应该真正添加以下内容:

print "\n";
注意,没有参数的睡眠是无限期睡眠的[2],所以我不知道为什么要使用它

当连接到终端时。它从块缓冲区开始,否则

或者,如果定义了信号处理程序,则直到信号传入


$then-$tdst-$ndst*60*60;看起来像输入错误。始终使用警告;严格使用,;在Perl代码中,您似乎没有使用严格的;或使用警告;正在使用中。您没有显式检查文件打开错误,也没有使用autodie;。这些都是潜在的问题。基本调试建议您在读取行时打印出行,然后在拆分后打印出字段,以确保您的程序达到预期效果。@serenesat:textfile是一种老式的非词法文件句柄,类似于STDERR、STDOUT、STDIN,但是合法的。按照惯例,它们是大写的,但这是惯例,不是必要性-AFAICR。任何进一步的评论都很难-你展示的不是MCVE,你也没有展示任何触发问题的最小化样本数据。谢谢。但是我想我刚刚在test.pl第82行、第46256行的print中找到了关于perl使用未初始化值的警告。在test.pl第83行、第46256行的打印中使用未初始化值。在test.pl第84行、第46256行的打印中使用未初始化值。当我打印的最后一行。。它没有显示任何东西。我想我找到了解决办法
select()->flush();
print "\n";