Re: File Locked after Close?

[email protected] (Rob Dixon)
Newsgroups perl.beginners
Message-ID <[email protected]>
[email protected] wrote:
> 
> I'm doing the following:
> 
> open FILE, '<file.dat' || die '...';
> # Do something with FILE
> close FILE;
> system 'command file.dat'; # This fails
> 
> The last line fails even though I closed FILE.  However, if I break
> out the last line into a separate script that is run later, it runs
> fine.  Therefore, it looks like there is some kind of lock that is
> left on FILE even though I closed it.
> 
> If I open another file with the same handle, then everything works.
> For instance:
> 
> open FILE, '<file.dat' || die '...';
> # Do something with FILE
> close FILE;
> open FILE, 'another.dat' || die '...';
> system 'command file.dat'; # This works
> 
> Unfortunately this is too awkard, so I would like to avoid it.  Any
> ideas on what may be happening or a more elegant way to ensure the
> problem (lock?) doesn't occur?  If it helps, I'm using an older build
> of ActiveState Perl (sorry, don't recall the version) on a WinXP
> system, running in a DOS shell.

It may be as well to update to ActivePerl v5.8, but check what version you have with

  perl -v

It's also a good idea to check the status of the closure

  close FILE or die "Unable to close file: $!";

HTH,

Rob
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.