On 01/20/2015 10:03 PM, Brandon McCaig wrote:
Uri Guttman, the author of File::Slurp, insists that it performs
much better than the standard Perl solution of setting $/ to
undef. I don't have benchmarks to prove it, but I'm willing to
trust his expertise on this. I imagine if you inspect the code or
distribution you'll be able to make an educated decision for
yourself. I've never cared to.
and file::slurp comes with a script that runs benchmarks on many
variations of slurping in files.
At the very least, I'm sure it doesn't hurt, and it allows you to
replace a rather cryptic syntax (albeit, one that any Perl
programmer should understand) with something a bit more readable.
agreed. that is one of the main reasons to use file::slurp over the $/
code. speed is the other.
Consider using File::Slurp despite being able to code it up
yourself in pure Perl. If you're OK with getting the results as a
LIST then File::Slurp even supports a chomp option. Otherwise, I
suppose there's always s///, though I can't specdulate on the
performance of such an operation. For a file like .bashrc I'm
sure any of these differences are negligible. I might prefer
File::Slurp with the chomp option and joining the lines
afterward though.
it would be much faster to remove the newlines with a single s/// call
on the full file in a string. this is one of the reasons slurping (in
any method) is such a win. you can do work on the entire file very
quickly vs looping over lines and doing work on each one.
I suppose there's always Benchmark.pm to give you a hint about
what works better if it matters.
which is the module i use in the benchmark script.
now, i don't get the need to remove the newlines from a text file like
this. i saw someone corrected a misconception over what a slurped file
would look like. thinking a string can only hold a single line is very
limiting and perl is anything but limiting. i wouldn't even call it a
multiline string - it is just a longer string holding a file.
uri
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/