I'd never choose the second method. With the first, it's
immediately clear what it does. With the second, it isn't.
And somehow I doubt it's faster - it certainly doesn't look
like it, as you first make a list of all the lines, then
join them together, meaning you get more than double the
memory usage. I'd rather do
my $text = do {local (@ARGV, $/) = $file; <>};
"Still do it in Perl" isn't a goal, IMO.
Abigail | [reply] [Watch: Dir/Any] [d/l] |
For simple file read/write operation like in this example File::Slurp is the winner:
use File::Slurp;
my $text = read_file($filename);
--
Ilya Martynov
(http://martynov.org/)
| [reply] [Watch: Dir/Any] [d/l] |