Hmm, sorry, but your answer is off-topic. The OP is writing a Perl script for achieving a given result, and your answer is: "Don't do it! Use grep!" But the code presented by the OP is not just trying to grep one file. It is looking for files in a directory, modifying these files and writing output in other files in another directory. It seems a bit difficult to do all this with a simple grep or even a awk one-liner. Of course, you could wrap the grep or the awk one-liner in a bash or sh or ksh script, but then the "no programming argument" is gone, you might as well do it in Perl, and it is likely to be more efficient in Perl.
But there is an even more important factor: a Perl script, if well designed, is portable across different platforms. Even though the script shown by the OP has an (admittedly strange) "#! /usr/bin/perl -w" shebang line, the rest of the script seems to strongly indicate the OP is running her or his script under MS Windows, probably with Strawberry Perl. I pray you: how are you going to run a grep or a awk one-liner script under Windows (unless you are using Cygwin, but the OP does not seem to be doing that)? (Well, awk may probably have been ported under Windows, I do not know, but by far most Windows users don't have it.)
| [reply] [d/l] |
FYI, FWIW, several versions of awk have been ported to MS Windows. Until a few years ago, I used a version that was packaged along with make and a few other Unix tools as part of code generation application we use with many of our projects. We used the make and the awk from that package in our build scripts because everyone in the SW department had the package installed. Now we use Perl instead of awk (but still use make).
| [reply] |
| [reply] |
Yes, thank you for the information, RonW. As I said in my previous post, I suspected that awk had been ported to Windows, but it is probably not commonly available (in the sense that it is not natively there on a fresh Windows install, so that most users probably don't have it). OTOH, the OP has Perl installed, and Perl is able to do just about everything that awk can do (and much more), so that recommending awk did not make much sense in that specific case.
| [reply] |