Forums.ATC.no
Teknisk => Generelt teknisk => Emne startet av: ATC på 27. ſeptember 2008, 18:24 pm
-
When reading from a file handle into a scalar, data is only fetched one line at a time. To read the whole file I have to use an array and then join() it together. Isn't there an easier way?
-
Ofcourse there is :-)
Perl uses the built-in variable $/ for the line terminator to determine what a line is. To 'slurp' an entire file into a scalar, simply undef $/ like so:
my $temp = $/; # Keep for later
undef $/;
my $var = <$fh>;
$/ = $temp; # Restore default behaviour