read

Syntax

read FILEHANDLE, SCALAR, LENGTH, OFFSET
read FILEHANDLE, SCALAR, LENGTH
FILEHANDLEThe identifier for the file from which the data is read.
SCALARThe name of the variable where the data is stored after reading.
LENGTHThe number of characters of data to read.
OFFSETThe number of characters from the start of the file prior to the data to be read.
The read function returns the number of characters actually read, 0 at end of file, or undef if there was an error (in the latter case $! is also set). The SCALAR variable will be grown or shrunk so that the last character actually read is the last character of the scalar after the read.

An OFFSET may be specified to place the read data at some place in the string other than the beginning. A negative OFFSET specifies placement at that many characters counting backwards from the end of the string. A positive OFFSET greater than the length of SCALAR results in the string being padded to the required size with "\0" bytes before the result of the read is appended.


INPUT_RECORD_SEPARATOR

Syntax

$INPUT_RECORD_SEPARATOR
$RS
$/
The input record separator defines what a "line" is (newline by default). The input record separator treats empty lines as a terminator if set to the null string. An empty line cannot contain any spaces or tabs. You may set it to a multi-character string to match a multi-character terminator, or to undef to read through the end of file.

Setting it to "\n\n" means something slightly different than setting to "", if the file contains consecutive empty lines. Setting to "" will treat two or more consecutive empty lines as a single empty line. Setting to "\n\n" will blindly assume that the next input character belongs to the next paragraph, even if it's a newline. (Mnemonic: / delimits line boundaries when quoting poetry.)