| [reply] |
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.
| [reply] [d/l] [select] |
Then, print to $FH from $_, not from @line
Given the nature of rammohan's previous posts, I'd suggest that he avoid implicit contexts($_, @_) entirely until he gains further understanding of perl.
| [reply] |
open(my$FHw, '>','/home/Admin/Desktop/ram.txt') or die '$!';
This problem is fairly trivial in the context of the others that have been pointed out, but if this open operation ever fails, the literal characters $! are all that will ever be printed because '$!' is a non-interpolating string. See Quote and Quote-like Operators in perlop.
| [reply] [d/l] [select] |
thank you! your suggestion works fine | [reply] |