$/="" is used to instruct Perl to read a paragraph. A paragraph is a block of text composed of two or more line breaks. This differs from setting to "nn", which only reads in blocks of text consisting of two lines. In this case, a problem will arise: if there are continuous blank lines, such as "textnnnn", you can interpret it as one paragraph ("text") or two paragraphs ("text" ", followed by two newlines, and an empty paragraph, followed by two blank lines.)
The second explanation is of little use when reading text. If the paragraph you are reading has the above situation, you do not need to filter out "empty" paragraphs.
$/="nn";
while(){
chomp;
nextunlesslength;#Skip empty segments
#...
}
You can set $/ to undef, it uses To read a paragraph followed by two or more newline characters: undef$/;
while(){
chomp;
#...
}
Read the entire file
$/ Other interesting values are undef. If set to this value, it will tell Perl that the read command will return the rest of the file as a string:
undef$/;
$file=;
Because changing the value of $/ will affect the future for each read operation, not just the next read operation. Usually, you want to limit this operation to a local one. Through the following example, the contents of the file handle can be read into a string:
{
local$/=undef;
$file=;
}
Remember: Perl variables can be read very long string. Although your file size cannot exceed the limit of your virtual memory capacity, you can still read in as much data as possible.
The above is the classic usage of Perl: reading the content of a paragraph. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!