search
HomeSystem TutorialLINUXTo read data from a file, the application first calls an operating system function

In file I/O, to read data from a file linux file handle, the application must first call the operating system function and pass the file name, and select a path to the file to open document. This function gets back a sequence number, that is, Perl file handle (filehandle) linux file handle . This Perl file handle is the only basis for identification of the open file. To read a piece of data from a file, the application needs to call the function ReadFile and transmit the address of the Perl file handle in video memory and the number of bytes to be copied to the operating system. When the task is completed, the file is closed by calling a system function.

Not only do you imitate a solipsist philosopher and write an artificial intelligence program, your program uses a method that does not communicate with the outside world. In the third and fourth lines of the class example, you will see "GRADES", which is a data type that refers to another Perl file, called a filehandle. A handle is a name you give a file, device, socket, or pipeline to help you remember the name you're working with and to hide the complexities of individual caches, etc. (Internally, handles are like streams in C, or I/O channels in BASIC.) Handles make it easy for you to input from and output to different places. One of the things that makes Perl a good language is its ability to communicate with multiple files and process them all at once. Having good symbolic names for external objects is an integral part of a good language [1].

Other things that make Perl a good language are: it is 8-bit, it is embeddable, and you can embed other programs in Perl through extension mode. It is concise and easy to use on the web. The environment is clear and easy to talk to. You can reference it in many different ways (as seen above). Actually, the language itself is not so strictly structured that you can't make it beyond your question. Back to TMTOWTDI again.

You create a handle and connect it to a file through the open function. open takes two parameters: the handle and the name of a file you want to link to it. Perl also provides some predefined (and pre-opened) handles. STDIN is the normal input channel of your program, and STDOUT is the normal output channel of your program. STDERR is an additional output channel so that the program can give some instructions when converting input to output [2].

Normally, these handles are linked to your terminal, so you can type your program and see it, but they can also be linked to files. Perl can give you this predefined handle because your operating system already provides it. Under UNIX, a process inherits standard input, output, and errors from its parent process (usually a shell). One of the responsibilities of a shell is to structure this I/O stream so that child processes don't have to worry about that).

linux文件句柄_句柄文件超多_句柄文件和文件句柄

Since you can use the open function to create handles for various purposes (input, output, pipeline), you must be able to specify what you want to do. Just like on the UNIX command line, you simply add characters to the file name.

Copy the code The code is as follows:

open(SESAME,"filename");#Read from an existing file

句柄文件超多_linux文件句柄_句柄文件和文件句柄

open(SESAME,"open(SESAME,">filename");#Create a file and write to it

open(SESAME,">>filename");#Continue writing to the existing file

open(SESAME,"|output-pipe-command");#Build an output filter

open(SESAME,"input-pipe-command|");#Build an input filter

As you heard, you can choose any name you want. Once a SESAME handle is opened, it can be used to access files or pipes until it is explicitly closed (with close(SESAME)), or a series of opens to the same handle links this handle to another file [3 ].

Opening an already open handle implicitly closes the first file, making it unavailable for Perl file handles, and opens a different file. You have to be mindful that this is what you really want to do. Sometimes, it happens that linux download tools happen by chance. For example, when you open($handle,$file), $handle happens to contain an empty string (null). Make sure to set $handle to a single value, otherwise you will open a new file with a null handle.

句柄文件超多_句柄文件和文件句柄_linux文件句柄

Once you have opened a handle for input (or you use STDIN), you can use the "line read operation" to read a line. This one is also known as a masonry operation, due to its shape. This masonry operation contains the handle()[4] you want to read. Use the STDID handle to read the answer provided by the user, as follows:

Empty masonry operation will read from all files specified on the command line. If not specified, read from STDIN. (This is standard behavior of many UNIX "filter" programs)

Copy the code The code is as follows:

句柄文件超多_句柄文件和文件句柄_linux文件句柄

printSTDOUT"Enteranumber:";#Request to enter a number

$number=;#Enter a number

printSTDOUT"Thenumberis$number";#Output this number

Do you understand the example we gave you? What does STDOUT do in the print sentence? This is one of the ways you use an output handler. A handle can be used as the first parameter of the print statement. If it exists, it tells where to output. In the example, the handle is redundant because the output is already STDOUT. The default for input is STDIN and for output is STDOUT. (We have omitted line 18 of the class counterexample to avoid confusing you.)

We also have one thing that you don't understand. If you try the example inside, you can notice that you get a very empty line. Because you did not manually remove the newline character from your input line when reading (for example, you entered "9"). For this case, when you want to remove newlines, Perl provides the chop and chomp functions. chop will indiscriminately delete (and return) the last character passed to it, while chomp will only delete the end of the record identifier (usually ""), and return the number of characters so deleted.

The above is the detailed content of To read data from a file, the application first calls an operating system function. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:ITcool. If there is any infringement, please contact admin@php.cn delete
How to Use 'next' Command with Awk in Linux - Part 6How to Use 'next' Command with Awk in Linux - Part 6May 15, 2025 am 10:43 AM

In this sixth installment of our Awk series, we will explore the next command, which is instrumental in enhancing the efficiency of your script executions by skipping redundant processing steps.What is the next Command?The next command in awk instruc

How to Efficiently Transfer Files in LinuxHow to Efficiently Transfer Files in LinuxMay 15, 2025 am 10:42 AM

Transferring files in Linux systems is a common task that every system administrator should master, especially when it comes to network transmission between local or remote systems. Linux provides two commonly used tools to accomplish this task: SCP (Secure Replication) and Rsync. Both provide a safe and convenient way to transfer files between local or remote machines. This article will explain in detail how to use SCP and Rsync commands to transfer files, including local and remote file transfers. Understand the scp (Secure Copy Protocol) in Linux scp command is a command line program used to securely copy files and directories between two hosts via SSH (Secure Shell), which means that when files are transferred over the Internet, the number of

10 Most Popular Linux Desktop Environments of All Time10 Most Popular Linux Desktop Environments of All TimeMay 15, 2025 am 10:35 AM

One fascinating feature of Linux, in contrast to Windows and Mac OS X, is its support for a variety of desktop environments. This allows desktop users to select the most suitable and fitting desktop environment based on their computing requirements.A

How to Install LibreOffice 24.8 in Linux DesktopHow to Install LibreOffice 24.8 in Linux DesktopMay 15, 2025 am 10:15 AM

LibreOffice stands out as a robust and open-source office suite, tailored for Linux, Windows, and Mac platforms. It boasts an array of advanced features for handling word documents, spreadsheets, presentations, drawings, calculations, and mathematica

How to Work with PDF Files Using ONLYOFFICE Docs in LinuxHow to Work with PDF Files Using ONLYOFFICE Docs in LinuxMay 15, 2025 am 09:58 AM

Linux users who manage PDF files have a wide array of programs at their disposal. Specifically, there are numerous specialized PDF tools designed for various functions.For instance, you might opt to install a PDF viewer for reading files or a PDF edi

How to Filter Command Output Using Awk and STDINHow to Filter Command Output Using Awk and STDINMay 15, 2025 am 09:53 AM

In the earlier segments of the Awk command series, our focus was primarily on reading input from files. However, what if you need to read input from STDIN?In Part 7 of the Awk series, we will explore several examples where you can use the output of o

Clifm - Lightning-Fast Terminal File Manager for LinuxClifm - Lightning-Fast Terminal File Manager for LinuxMay 15, 2025 am 09:45 AM

Clifm stands out as a distinctive and incredibly swift command-line file manager, designed on the foundation of a shell-like interface. This means that users can engage with their file system using commands they are already familiar with.The choice o

How to Upgrade from Linux Mint 21.3 to Linux Mint 22How to Upgrade from Linux Mint 21.3 to Linux Mint 22May 15, 2025 am 09:44 AM

If you prefer not to perform a new installation of Linux Mint 22 Wilma, you have the option to upgrade from a previous version.In this guide, we will detail the process to upgrade from Linux Mint 21.3 (the most recent minor release of the 21.x series

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment