-Are you sure you want to read the entire file and store it in memory?
-If you mmap the file, you can virtually load the entire file into a
-string without actually storing it in memory:
-
- use File::Map qw(map_file);
-
- map_file my $string, $filename;
-
-Once mapped, you can treat C<$string> as you would any other string.
-Since you don't necessarily have to load the data, mmap-ing can be
-very fast and may not increase your memory footprint.
-
-If you want to load the entire file, you can use the C<File::Slurp>
-module to do it in one one simple and efficient step:
-
- use File::Slurp;
-
- my $all_of_it = read_file($filename); # entire file in scalar
- my @all_lines = read_file($filename); # one line per element
-