Secondly wouldnt a grp pattern file be faster than reading the file line by line and pattern matching like this $_ =~ /^(04|05).
I doubt it. Grep has to read the entire file in, too, so you're not saving anything in disk access. There might be some speedup if grep on your system is implemented to read normally instead of line-by-line. Really, from a speed point of view, it will all come down to whichever program has a more optimized regex engine. In practice, the extra expense of just executing grep will probably make up for any lost speed.
Further, I wouldn't worry about speed at all. The pure-Perl soultion will work just fine. Relying on external programs like this is generally a Bad Thing (tm). There are many problems with using external programs, not the least of which is potential security issues. It also tends to make less maintainable code.
---- I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer
Note: All code is untested, unless otherwise stated
|