On Tue, 20 Jul 2004 07.25, Austin Hastings wrote: > --- Rod Adams <[EMAIL PROTECTED]> wrote: > > If I cannot open a file for writing (permissions, out of space, > > write locked, etc), I want to know the instant I attempt to open it > > as such, _not_ when I later attempt to write to it. Having all > > these features available to open as arguements seems a much better > > idea to me. It's "Open a file with these specifications", not "Open > > a file, and then apply these specifications to it". > > But why? Do you really open files and then perform an hour of work > before attempting to use them? I'll argue that's not the normal case; > rather, the normal case is something like > > open .... or die ... > other_stuff() > while (...) { > print ... > } > close > > and the intervening delay (other_stuff) is negligible in wall-clock > terms: when a failure occurs, the user hears about it immediately.
The issue isn't about how long it takes other_stuff() to run. The issue is whether other_stuff does something irrevocable that shouldn't have been done if the file couldn't be opened. Imagine a double-entry bookkeeping system that needs to atomically update two files at once. You don't want to discover that one file is inaccessible after you've already written the transaction to the other file. You'd end up circumventing the DWIMmery by writing empty strings to the files just to make sure they exist: $handle1 = open "file1"; $handle2 = open "file2"; print $handle1: ""; # Did it really open? print $handle2: "transaction 2" or die; print $handle1: "transaction 1" or die; I contend that however many examples you could come up with that make "open-on-write" look neat, it's possible to contrive just as many examples that make "open-on-write" look awkward. Which, IMHO, is a perfect argument for putting this functionality into a library where those who want to use it, will. It's probably time to leave all of this up to @Larry to concoct something that everyone's happy with. -- Debbie Pickett http://www.csse.monash.edu.au/~debbiep [EMAIL PROTECTED]