Home > php教程 > PHP开发 > Classic usage of Perl: reading multiple records

Classic usage of Perl: reading multiple records

黄舟
Release: 2016-12-16 13:49:20
Original
1256 people have browsed it

If you call, return the remaining records in the file. If you are at the end of the file, an empty table is returned:

@records=;

if(@records){

PRint"Therewere",scalar(@records),"recordsread.n";

}

at In the next step, assignment and testing are performed:

if(@records=){

print"Therewere",scalar(@records),"recordsread.n";

}

chomp() also Applicable array operations:

@records=;

chomp(@records);

For any expression, chomp operation can be performed, so you can write like this in the next step:

chomp(@records =);

What is a record?

The default definition of a record is: "row".

The definition of the record is controlled by the $/ variable, which stores the separator of the entered record. Because the newline character (by definition!) is used to separate lines, its default value is the string "n".

For example, you can replace "n" with any symbol you want to replace.

$/=";";

$record=;#Read the next record separated by semicolon

$/ can take on two other interesting values: empty string ("") and undef

above This is the classic usage of Perl: reading the contents of multiple records. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template