More controls with sysopen () --------------------------------------- --------------------------------------- For better control files, you can Use the sysopen () function: use fcntl; sysopen (fH, $ filename, o_rdwr | o_creat, 0666) or die "can't open $ filename forreading / write / create: $!"; Function sysopen () has four Parameters, the first is the file handle parameter similar to the open () function, the second parameter is the file name without mode information, the third parameter is the mode parameters, the constant combined by the logic OR operation provided by the FCNTL module Composition, the fourth parameter (optional), for the octatifact property value (0666 represents the data file, 0777 represents the program). If the file can be opened, sysopen () returns true if the file fails, then returns false. Unlike the open () function, Sysopen () does not provide a mode description, but combines some constants, and each mode constant has a unique meaning, only through logic OR operations, can combine them, you can Set a combination of multiple behaviors. O_RDONLYRead-only O_WRONLY Write-only O_RDWR Reading and writing O_APPEND Writes go to the end of the file O_TRUNC Truncate the file if it existed O_CREAT Create the file if it did not exist O_EXCLError if the file already existed (used with O_CREAT) when you When you need careful, use the sysopen () function, for example, if you intend to add content to the file, if the file does not exist, you don't have a new file, you can write: sysopen (log, "/ var / log / myprog .log ", o_append, 0666) OR DIE" can't open /var/log/myprog.log for appending: $! ";