search
Homephp教程PHP开发Classic usage of Perl: Use Sysopen() for more control

In order to better control how files are opened, you can use the sysopen() function:

useFcntl;

sysopen(FH,$filename,O_RDWR|O_CREAT,0666)

ordie"Can'topen$filenameforreading/writing/creating :$!";

The function sysopen() takes four parameters. The first parameter 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 parameter is composed of constants combined with the logical OR operation provided by the Fcntl module. The fourth parameter (optional) is an octal attribute value (0666 represents the data file, 0777 represents the program). sysopen() returns true if the file can be opened, false if the file fails to be opened.

Different from the open() function, sysopen() does not provide an abbreviation for mode description, but combines some constants. Moreover, each mode constant has a unique meaning, and they can only be combined through logical OR operations. You can set up a combination of multiple behaviors.

O_RDONLYRead-only

O_WRONLYWrite-only

O_RDWRReadingandwriting

O_APPENDWritesgototheendofthefile

O_TRUNCTruncatethefileifitexisted

O_CREATCreatethefileifitdidn'texist

O_EXCLErrorifthefilealreadyexisted(usedwithO_CREAT)

Use the sysopen() function when you need to be careful, for example, if You plan to add content to the file. If the file does not exist, without creating a new file, you can write like this:

sysopen(LOG,"/var/log/myPRog.log",O_APPEND,0666)

ordie"Can' topen/var/log/myprog.logforappending:$!";

The above is the classic usage of Perl: using Sysopen() for more control. For more related articles, please pay attention to the PHP Chinese website (www.php.cn )!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor