Possible Duplicate:
What is the best way to slurp a file into a string in Perl?
Is this code a good way to read the contents of a file into a variable in Perl? It works, but I’m curious if there is a better practice I should be using.
open INPUT, "input.txt";
undef $/;
$content = <INPUT>;
close INPUT;
$/ = "\n";
I think common practice is something like this:
Using 3 argument
openis safer. Using file handle as variable is how it should be used in modern Perl and usinglocal $/restores initial value of$/on block end, instead of your hardcoded\n.