leonidlm has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I have a problem with one very simple task. I run a scheduled script that checks an application server log for some regExp and stores the end of the file (tell/seek) to continue checking the log from the place it finished before. The problem is that from time to time the server is dropping a line that makes the script stop there (thinks it is an EOF or something)! it is a huge line with some strange unformatted text, even when I try to copy/paste it in textpad i get: "cann't copy ... containing null (code = 0) character". What can I do? I can't bypass this line! here is a main loop code:
while (<LOGFILE>) { #print "$_"; # Found the "PWorld.dumper - total" string in one of the lines if ($_ =~ /(\d{2}):(\d{2}):(\d{2}).+PWorld\.dumper - total/) { $sec = $3; $min = $2; $hour = $1; $tempTime = timelocal($sec,$min,$hour,$day,$mon-1,$year); if ($storedDumpLastTime != 0) { $delta = ($tempTime - $storedDumpLastTime); # delta in +seconds! $lastTime = scalar localtime($storedDumpLastTime); $currTime = scalar localtime($tempTime); $cmdDumpDelta = "opcmon $tag=$delta -object dumpDelta -opt +ion lasttime=\"$lastTime\" -option currtime=\"$currTime\""; } $storedDumpLastTime = $tempTime; $dumpedToday = 1; } #print "line: $_"; } # Store the EOF in the configuration file as the next start point $storedCurrPlace = tell(LOGFILE); close(LOGFILE);
Thanks

Replies are listed 'Best First'.
Re: null character problem
by zentara (Cardinal) on Sep 03, 2007 at 16:54 UTC
      Thank you for you'r reply but I still have a problem with this. The reason is that the while loop stops at this Evil line! The loop is not continuing till the end of the file but stops before, somehow perl thinks this null character is the EOF.
        You need to strip the null byte out before you run it thru the while loop.

        I'm not really a human, but I play one on earth. Cogito ergo sum a bum