Günter Laudenklos: Ein Graus - File lock

Beitrag lesen

Hallo Michel,

und jetzt haette ich noch gern gewusst wie diese Funktion eine Datei erzeugt wenn sie nicht existiert. Das macht sie naemlich nicht.
Ansonsten habe ich sie schon recht erfolgreich am Laufen (bisher ist alles heil geblieben).
Nun habe ich es so geloest, dass ich vorher checke ob die Datei existiert und wenn nicht mit open (FILE, ">>datei.dat");close(FILE); diese erzeuge. Erscheint mir aber nicht sehr elegant.

ich wüßte auch keinen besseren Weg als

if(!stat($file))
{
 open (FILE,">$file");  # create file
 close (FILE;
}

open (FILE,"+<$file") or die();

....
...
..

Da ich zwar ">>" und ">" und "<" verstehe, nicht aber "+<" weiss ich nicht recht was ich machen muss.

Zitat:
If the filename begins with '<' or nothing, the file is opened for input. If the filename begins with '>',
the file is truncated and opened for output, being created if necessary. If the filename begins with
'>>', the file is opened for appending, again being created if necessary. You can put a '+' in front
of the '>' or '<' to indicate that you want both read and write access to the file; thus '+<' is
almost always preferred for read/write updates--the '+>' mode would clobber the file first. You can't
usually use either read-write mode for updating textfiles, since they have variable length records. See the
-i switch in perlrun for a better approach. The file is created with permissions of 0666 modified by the
process' umask value.

Viele Grüße Günter