Ok, I've counted to 100 to let my first instincts become less likely to come out in this post..... so here goes.

You have to decide whether you want to iterate over a file line by line, or slurp the whole thing into an array. If you try to do both, you'll probably end up with a big bug, which is what you have. So, remove "my@line = <STDIN>;". Then, print to $FH from $_, not from @line, since you've now removed the line of code that declares that variable and slurps into it. Then shift the line where you close $FH to after the loop, not inside its body. Doing those things should clear up the bugs that are really obvious. I'm unclear on what you actually want your code to do, but the first step is to at least rid yourself of the bugs that no code should ever do. ;)

As for how to eliminate empty lines, well, that's pretty simple. Since your new code that has applied the fixes I described is now iterating line by line over the file, just look for empty lines, and don't "print" to your output filehandle when such lines are detected. There are several ways to accomplish this. You could chomp your input, and then use length to detect empty lines, or you could use a regular expression to detect empty lines. But whatever method you use for detecting empty lines, the logic will be the same; if an empty line is detected, do not print it back out to your output filehandle.


Dave


In reply to Re: How to eliminate the empty lines while giving user input from terminal by davido
in thread How to eliminate the empty lines while giving user input from terminal by rammohan

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.