Search⌘ K

Special File Handling Variables

Explore how to manage file input and output efficiently in Perl using special variables like $., $/, and $|. Understand line counting, custom input record separators, and output buffering control to write responsive, real-world Perl programs.

$. or line counter

For every line read, Perl increments the value of the variable $., which serves as a line counter.

Perl
open my $fh, '<', 'some_file';
while (<$fh>) {
print " $.";
}

$/ or line-ending sequence

readline uses the current contents of $/ as the line-ending sequence. The value of this variable defaults to the most appropriate line-ending character sequence for text files on our current platform. The word line is a misnomer, however. $/ can contain any ...