Your reply indicates a number of misunderstandings. I hope you don't mind my pointing them out as a learning exercise.
  1. If you are not sure that a pipe will open, the last thing you want to do is hope that it works. Instead do as perlstyle says and put in an informative error check. Preferably using die and showing the contents of $!.
  2. Perl style foreach loops alias each element of the array to a variable. Modifications of that variable affect the original array element. Therefore the loop is not useless.
  3. The last semi-colon in a block is optional.
  4. Do not use a map or grep if you are not using the return value. It wastes memory, runs slower, and is less intuitive. And if you really want the inline loop, just write it:
    s/foo/bar/g foreach @list;
  5. Avoid C-style for loops whenever you have the opportunity to use more Perlish foreach loops. According to several studies, the most common error in C is to have an off-by-one error in a for loop. Just loop over an array using the direct foreach and it will both execute faster and you can't make an off-by-one error.
Now a few other general comments about the problem. First of all your removal of the hardcoded 45 is a good thing. Hard-coded numbers are a danger sign. Secondly it is a good habit to make everything run with strict.pm, which none of this code does. For short examples the benefits are not that great. Longer code is a different story. Thirdly I have to wonder whether it really makes sense to append together lines which have whitespace stripped from front and back to each other without some space to divide them. And finally, is $nl being printed? I don't see it being printed, and if it isn't, then the entire script becomes of dubious value at best.

In reply to Re (tilly) 2: script debug by tilly
in thread script debug by Anonymous Monk

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, details, 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, summary, 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.