Perl sysopen Function



This function is equivalent to the underlying C and operating system call open( ). Opens the file specified by FILENAME, associating it with FILEHANDLE. The MODE argument specifies how the file should be opened. The values of MODE are system dependent, but some values are historically set. Values of 0, 1, and 2 mean read-only, write-only, and read/write, respectively. The supported values are available in the Fcntl module, and are summarized in below Table.

Note that FILENAME is strictly a file name; no interpretation of the contents takes place (unlike open), and the mode of opening is defined by the MODE argument.

If the file has to be created, and the O_CREAT flag has been specified in MODE, then the file is created with the permissions of PERMS. The value of PERMS must be specified in traditional Unix-style hexadecimal. If PERMS is not specified, then Perl uses a default mode of 0666 (read/write on user/group/other).

Flag		Description
O_RDONLY 	Read only.
O_WRONLY 	Write only.
O_RDWR 		Read and write.
O_CREAT		Create the file if it doesn.t already exist.
O_EXCL 		Fail if the file already exists.
O_APPEND 	Append to an existing file.
O_TRUNC 	Truncate the file before opening.
O_NONBLOCK 	Non-blocking mode.
O_NDELAY 	Equivalent of O_NONBLOCK.
O_EXLOCK 	Lock using flock and LOCK_EX.
O_SHLOCK 	Lock using flock and LOCK_SH.
O_DIRECTOPRY 	Fail if the file is not a directory.
O_NOFOLLOW 	Fail if the last path component is a symbolic link.
O_BINARY 	Open in binary mode (implies a call to binmode).
O_LARGEFILE 	Open with large (>2GB) file support.
O_SYNC 		Write data physically to the disk, instead of 
		write buffer.
O_NOCTTY 	Don't make the terminal file being opened 
	 	the processescontrolling terminal, even if you 
	 	don.t have one yet.


Following is the simple syntax for this function −



Return Value

This function returns 0 on failure and 1 on success.