Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl file handling and Windows 98

Status
Not open for further replies.

canedandunable

Programmer
Joined
Jul 17, 2002
Messages
1
Location
GB
Hi,

I don't use Perl that often except to generate text files for testing of embedded systems. I currently have an application that creates a file which is emitted to a system which provides a reply. I parse the reply and check against what was sent. In the meantime, I append a log file with results from the operation.

It is the log file which is causing a problem and I think it has to do with file locking and Windows 98.

The code which appends the log file is:

sub AppendLogFile
{
my $StringToWrite = shift;
my $filehandle = new IO::File;

$filehandle->open(">>$LogFilename") or die "No such file : $LogFilename\n\r";

my $timestr;
my @dantime = localtime();

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();

$timestr = "";
$timestr .= sprintf("%02d", $hour).":";
$timestr .= sprintf("%02d", $min).":";
$timestr .= sprintf("%02d", $sec)." ";
$timestr .= sprintf("%02d", $mday)."/";
$timestr .= sprintf("%02d", $mon);

if($StringToWrite eq "BLANK")
{
$filehandle->print("\n\r") or print "Unable to write blank line to file $LogFilename\n\r";
print "\n\r";
}
else
{
$filehandle->print($timestr." : ".$StringToWrite."\n\r") or print "Unable to write data to $LogFilename\n\r";
print $timestr." : ".$StringToWrite."\n\r";
}
$filehandle->close();
}

which is called as:

AppendLogFile("Some message");


It seems that after a while, Windows decides that the file is in use and won't allow Perl to write any more data to it; attempting to delete the file via the OS warns that the file is in use by the OS.

So, it would seem that Perl is not closing the file properly when it has been finished with. Is there some mechanism I need to employ to overcome this?

I have used the same code on a Linux box with no problems in the past.....

Regards,
Dan
 
Looks ok to me as well, are you still having this problem? Mike
________________________________________________________________

"Experience is the comb that Nature gives us, after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top