How to read only the first line of a file

Lukasz Madon picture Lukasz Madon · Aug 11, 2011 · Viewed 54.2k times · Source

I've been googling for a while, but I cannot find a function the read just first line of a file.

I need to read first line of a text file and extract the date from it.

new to perl.

Answer

wespiserA picture wespiserA · Aug 11, 2011
open my $file, '<', "filename.txt"; 
my $firstLine = <$file>; 
close $file;