[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Newbie question



on 9/28/00 11:40 PM, Bruce Axtens at bruce_axtens@sil.org wrote:

> Dear List
> 
> How do I tell if a file is still open. I'm watching a shared folder and I
> want to be able to tell whether an incoming file is still open or closed.
> 
> Thanks,
> 
> Bruce.
> 

Take this with a grain of salt, since I only started learning Perl this
week, but based on the following from the perlfunc manpage...

Open returns nonzero upon success, the undefined value otherwise.

..it seems to me that

if (open('+<filename')) { do whatever you want to do when the file is closed
} else { do whatever you want to do if the file is still open }

or

until (open('+<filename')) { }

should work, i.e. open('+<filename') should evaluate to false in a Boolean
context if some other process has the file open for writing. I'm assuming
that the "undefined value" mentioned above evaluates to false in a Boolean
context, which only makes sense but I have yet to test that theory myself.
I'm also assuming that Perl will refuse to open a file for writing that
already is, which also seems reasonable.

Hope this helps.


Rusty


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org