6 Ways to Read a Text File into a VariableIf you are working with large file(s) you might consider using File::Slurp. {
local $/=undef;
open FILE, "myfile" or die "Couldn't open file: $!";
binmode FILE;
$string = <FILE>;
close FILE;
}
|
|
|
open FILE, "myfile" or die "Couldn't open file: $!";
while (<FILE>){
$string .= $_;
}
close FILE;
|
The format for the read function is: read(filehandle, destination, size/length); The example above will read 2000 bytes into the scalar variable $data. |
|