Andy: On Tue, Jan 20, 2015 at 05:56:26PM -0600, Andy Bach wrote: > my $contents = do { local $/; map { chomp } <HANDLE> }; > > sorry, untested.
chomp() returns a number representing the number of removed characters unfortunately. Your block would need to return $_ separately. (I find this rather annoying, but surely a CPAN module has "fixed" this with an altenative that returns the string...) my $contents = do { local $/; map { chomp;$_ } <$fh> }; * * * 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. 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. 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. I suppose there's always Benchmark.pm to give you a hint about what works better if it matters. Regards, -- Brandon McCaig <bamcc...@gmail.com> <bamcc...@castopulence.org> Castopulence Software <https://www.castopulence.org/> Blog <http://www.bambams.ca/> perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }. q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.}; tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say'
signature.asc
Description: Digital signature