On 9/29/00 1:59 PM -0500, Rusty <CoDeReBeL@hotmail.com> wrote: >on 9/29/00 1:31 PM, Paul Schinder at schinder@pobox.com wrote: > >> At 12:45 PM -0500 9/29/00, <CoDeReBeL@hotmail.com> wrote: >>> I'm also assuming that Perl will refuse to open a file for writing that >>> already is [open], which also seems reasonable. >> >> This depends entirely on the operating system. It certainly isn't >> true under Unix, where you can open a file for writing as many times >> as you want. It may or may not be true for MacPerl. You might be >> able to find out from Mac OS using a toolbox call. >> >> Paul Schinder >Overwhelmed with curiosity, I decided to find out what the deal was. If any >process *except* MacPerl has a file open for writing, then > >open (WHATEVER, '+<theFileName') > >returns false. If, however, the process that has the file open for writing >is MacPerl itself, it returns true. I used MPW in the test. Presumably, >standalone applications and droplets count as separate processes. It's not that simple. For example, if BBEdit has a file open, it doesn't exclude my Perl scripts from opening and writing to that file. If it's opened first in BBEdit and then in Excel, Excel can write to it (save), but BBEdit can't (until Excel closes it). I don't know the innards of file locking on Mac, but from the different behavior of BBEdit and Excel, it seems that there's the possibility of opening a file for reading and writing with or without locking it. Or perhaps BBEdit opens it and only reads it (into memory) and then opens it again when it comes time to save, whereas Excel opens it and locks it until closing. Keep in mind that Perl has several ways of opening files, (only read, only write, read and then write, write and then read, append). You might also want to study up on Perl's approach to file locking (flock), which, as Programming Perl says, takes a cooperative approach to locking, like traffic signals, which work if everyone follows the rules, but not in the case of a driver who is "rude, ignorant, or desperate." The upshot of this is that Rusty's idea of using the 'open' command's return value to find out if a file is already open is _not_ the way to do it :-). Maybe the original poster -- still listening? -- could clarify the reason for their question about how to tell if a file is already open. What are you trying to do? Maybe you need Perl's 'tell' and 'seek' commands, for controlling where in the file you're reading or writing? 1; - Bruce _Bruce_Van_Allen___bva@cruzio.com__Santa_Cruz_CA_ # ===== Want to unsubscribe from this list? # ===== Send mail with body "unsubscribe" to macperl-request@macperl.org