On Thu, Sep 2, 2010 at 13:08, Uri Guttman <u...@stemsystems.com> wrote:
snip
> for the excluded hash, it is simpler and probably much faster than line
> by line. the latter way needs to run much more perl code which is slower
> than a single slice. i won't benchmark it because it is also better
> coding which is more important. the other file could be line by line but
> i stuck with this paradigm for the moment.
snip

You may think there is more code in the while loop version, but really
it there is less.  File::Slurp is a pure Perl module.  That means that
whatever loop it is using to get the data must happen in Perl.  Then
you copy that data to an array, then the hash slice has to iterate
over the array.  You have three loops (two of which are in C), but the
while loop has one.  Using File::Slurp to get an array is slower than
dumping the file handle into an array.  File::Slurp may be faster than
a straight slurp when slurping to a scalar, but I doubt it.
File::Slurp's only real advantage is that

my $string = read_file "filename";

is easier to understand than

my $string = do {
   open my $fh, "<", "filename" or die $!;
   local $/;
   <$fh>;
};


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to