|P is for Practical|
Re: Removing blank/empty linesby marquezc329 (Scribe)
|on Dec 11, 2012 at 17:37 UTC||Need Help??|
"I just want to omit them and tried chomp but it didn't work ..."This is because chomp is used to remove trailing strings (most often, newlines) from records. So instead of removing the blank line, it removes the trailing newline at the end of the blank line resulting in an empty string.
As stated by Anonymous Monk above, you could use a regex to rewrite
or even (depending on how much you trust your data),
Have a look at perlretut if you need help understanding basic regexs.
On a side note, your code will be much easier to read and debug if you adopt a style that uses proper indentation. The indentation will help you to better visualize conditional blocks and control structures, as well as help you to gain a better understanding of variable scope.
Here's a sample rewrite fixing the indentation with a few small modifications.