in reply to Re^3: Why i am not able to print any statment after while loop
in thread Why i am not able to print any statment after while loop

Hi Laurant,

I am sorry but stil not working in my Laptop. Please see snapshot. http://prntscr.com/5txpl6 Neither it even not render output in ListOfIpAdress2.txt now and also not deleting ListOfIpAdress.txt

Here is my full code:

use strict; use Time::Local; use warnings; my $counter = 0; my($address) = @_; my $str; my $flag=0; my $file = 'C:\shekhar_Axestrack_Intern\WindowCreation\ListOfIpAdress2 +.txt'; open my $fho, '>', 'C:\shekhar_Axestrack_Intern\WindowCreation\ListOfI +pAdress2.txt' or die "Could not open file $!"; open my $fhi, '<', 'C:\shekhar_Axestrack_Intern\WindowCreation\ListOfI +pAdress.txt' or die "Could not open file $!"; while (my $line = <$fhi>) { 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 > 41; } 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"; } }
Any Idea why ?

Replies are listed 'Best First'.
Re^5: Why i am not able to print any statment after while loop
by Laurent_R (Canon) on Jan 18, 2015 at 13:03 UTC
    Your $file variable contains the name of the output file, so that when you do:
    unlink ($file);
    you actually delete the output file instead of deleting the input file.

    Otherwise, don't worry too much about the "uninitialized" warnings you get (in your screen shot), they are most probably due to an empty line at the end of your input file, so that the $sMonth, $sDate, $sTime variables don't get populated for that empty line. Just add a line like this:

    next unless defined $sMonth;
    after the split (just after line 14), and this should suppress these warnings.

    Je suis Charlie.
Re^5: Why i am not able to print any statment after while loop
by ppp (Acolyte) on Jan 18, 2015 at 12:30 UTC
    Sorry it prints the IP address in ListOfIpAdress2.txt ON CHANGING (36 TO 42 because it only prints the line whose TIME IS LESS THAN 42).

    But it still do not delete the ListOfIpAdress.txt Why that i dont know yet.