> I just can't figure this out: how do I overwrite an exisitng file
> without creating a new version?  I.e., if x.;1 exists I want perl
> to use that and replace the contents.  But when I try that
> I get:

> $ perl -e "open(X,"">x.;1"") || die; printf X ""blabla"";
> Died at -e line 1.
> %RMS-E-FEX, file already exists, not superseded


> I couldn't find anything in perldoc perlvms or the web,
> please help.

This whole idea makes me nervous.  You seem to be trying to mimic Unix
filesystem behavior, and I really appreciate RMS versioning.  RMS versioning
would let multiple instances of your program run at the same time without
getting their hands crossed.

Are you sure that only one instance of your program will run at a time?  Are
you sure that the contents of this file will have no value past the end of that
run of the program?  (If so, why not have a cleanup routine that unlinks the
file when the program exits?)

Enough angst.  My best answer:

I don't know if there's a special incantation that will make this happen;
I know (from experience, and because it's what I usually want) that 
">> x" will append to an existing file or create a new one if it doesn't exist.

But you could probably ">> x" and then do whatever the standard perl operation
for truncate/erase/rewind is, and go from there.

Or you could unlink (delete, in VMS-think) the file, throw away the status
return, and then open the file fresh.  (Safer (because you might get a status
other than "doesn't exist", like "locked by somebody else", so your open would
fail), but less one-liney, to stat it first and unlink it if it exists, but
this is even less atomic than just unlinking, so if you _are_ worried about
multiple instances of your program, it's not a great idea.)

-- Alan

-- 
===============================================================================
 Alan Winston --- [EMAIL PROTECTED]
 Disclaimer: I speak only for myself, not SLAC or SSRL   Phone:  650/926-3056
 Paper mail to: SSRL -- SLAC BIN 99, 2575 Sand Hill Rd, Menlo Park CA   94025
===============================================================================

Reply via email to