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.)

Je suis Charlie.

In reply to Re^2: Remove whitespace between lines by Laurent_R
in thread Remove whitespace between lines by wrkrbeee

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.