and I do get the following output:use strict; use Time::Local; use warnings; my $counter = 0; my($address) = @_; my $str; my $flag=0; my $file = 'C:\ListOfIpAdress.txt'; open my $fho, '>', 'ListOfIpAdress2.txt' or die "Could not open file $ +!"; while (my $line = <DATA>) { my ($a1, $a2, $a3, $Day, $sMonth, $sDate, $sTime, $SYear,$a9, $a1 +0) = split(/ {1,}/, $line); my $str1= $sMonth." ".$sDate." ".$sTime ; my $scTime = localtime; my ( $cDay, $cMonth, $cDate, $cTime, $cYear,$Syear) = split(/ {1, +}/, $scTime); my $str2= $cMonth." ".$cDate." ".$cTime ; use constant Year => 2015; my $t1 = convert($str1); my $t2 = convert($str2); my $Diff= $t2 - $t1; my $div = $Diff/3600; print "Total Difference in Hour is : $div \n\n"; print $fho $line unless $div > 38; } print "\nn check1 \n\n"; close $fho; print "\nn check2 \n\n"; unlink ($file); if(-e $file) { print "File still exists!"; } else { print "File gone."; } sub convert { my $dstring = shift; my %m = ( 'Jan' => 0, 'Feb' => 1, 'Mar' => 2, 'Apr' => 3, 'May' => 4, 'Jun' => 5, 'Jul' => 6, 'Aug' => 7, 'Sep' => 8, 'Oct' => 9, 'Nov' => 10, 'Dec' => 11 ); if ($dstring =~ /(\S+)\s+(\d+)\s+(\d{2}):(\d{2}):(\d{2})/) { my ($month, $day, $h, $m, $s) = ($1, $2, $3, $4, $5); my $mnumber = $m{$month}; # production code should handle erro +rs here timelocal( $s, $m, $h, $day, $mnumber, 1900 ); } else { die "Format not recognized: ", $dstring, "\n"; } } __DATA__ Address: 100.64.52.98 Time Fri Jan 16 21:44:35 2015 End Address: 100.65.0.172 Time Fri Jan 16 21:46:48 2015 End Address: 100.64.58.219 Time Fri Jan 16 22:56:16 2015 End Address: 100.65.5.25 Time Fri Jan 16 23:10:04 2015 End Address: 100.64.8.184 Time Fri Jan 16 23:52:54 2015 End Address: 100.65.13.135 Time Fri Jan 16 23:59:46 2015 End
And the ListOfIpAdress2.txt is duly created:$ perl logs.pl Total Difference in Hour is : 37.5744444444444 Total Difference in Hour is : 37.5375 Total Difference in Hour is : 36.3797222222222 Total Difference in Hour is : 36.1497222222222 Total Difference in Hour is : 35.4358333333333 Total Difference in Hour is : 35.3213888888889 n check1 n check2 File gone.
I do not know if this the result you are looking for, but I don't get the error you are reporting.$ cat ListOfIpAdress2.txt Address: 100.64.52.98 Time Fri Jan 16 21:44:35 2015 End Address: 100.65.0.172 Time Fri Jan 16 21:46:48 2015 End Address: 100.64.58.219 Time Fri Jan 16 22:56:16 2015 End Address: 100.65.5.25 Time Fri Jan 16 23:10:04 2015 End Address: 100.64.8.184 Time Fri Jan 16 23:52:54 2015 End Address: 100.65.13.135 Time Fri Jan 16 23:59:46 2015 End
In reply to Re: Why i am not able to print any statment after while loop
by Laurent_R
in thread Why i am not able to print any statment after while loop
by ppp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |