I have a small text file that I\'d like to read into a scalar variable exactly as it is in the file (preserving line separators and other whitespace).
The equivalent
As an alternative to what Alex said, you can install the File::Slurp module (cpan -i File::Slurp
from the command line) and use this:
use File::Slurp;
# Read data into a variable
my $buffer = read_file("fileName");
# or read data into an array
my @buffer = read_file("fileName");
Note that this die
s (well... croaks, but that's just the proper way to call die from a module) on errors, so you may need to run this in an eval block to catch any errors.