You are viewing the version of this documentation from Perl 5.005_03. View the latest version
input_record_separator HANDLE EXPR
$INPUT_RECORD_SEPARATOR
$RS
$/

The input record separator, newline by default. This is used to influence Perl's idea of what a "line" is. Works like awk's RS variable, including treating empty lines as delimiters if set to the null string. (Note: An empty line cannot contain any spaces or tabs.) You may set it to a multi-character string to match a multi-character delimiter, or to undef to read to end of file. Note that setting it to "\n\n" means something slightly different than setting it to "", if the file contains consecutive empty lines. Setting it to "" will treat two or more consecutive empty lines as a single empty line. Setting it to "\n\n" will blindly assume that the next input character belongs to the next paragraph, even if it's a newline. (Mnemonic: / is used to delimit line boundaries when quoting poetry.)

undef $/;		# enable "slurp" mode
$_ = <FH>;		# whole file now here
s/\n[ \t]+/ /g;

Remember: the value of $/ is a string, not a regexp. AWK has to be better for something :-)

Setting $/ to a reference to an integer, scalar containing an integer, or scalar that's convertable to an integer will attempt to read records instead of lines, with the maximum record size being the referenced integer. So this:

$/ = \32768; # or \"32768", or \$var_containing_32768
open(FILE, $myfile);
$_ = <FILE>;

will read a record of no more than 32768 bytes from FILE. If you're not reading from a record-oriented file (or your OS doesn't have record-oriented files), then you'll likely get a full chunk of data with every read. If a record is larger than the record size you've set, you'll get the record back in pieces.

On VMS, record reads are done with the equivalent of sysread, so it's best not to mix record and non-record reads on the same file. (This is likely not a problem, as any file you'd want to read in record mode is probably usable in line mode) Non-VMS systems perform normal I/O, so it's safe to mix record and non-record reads of a file.

Also see $..