in reply to Remove whitespace between lines
as follows:while (my $line = <$fh_in>) { my $text = $line; chomp ($text); #Strip/remove whitespace between lines of text file; while (<STDIN>) { print if (!/^\s*$/); } print $fh_out "$text\n"; #Save stripped results; }
Update: Sorry, I wrote that above message on my mobile device in the train commuting back to home, the train was arriving near my town, so I copied and pasted the code a bit to hastily. The above code should be:while (my $line = <$fh_in>) { print $fh_out $line if (!/^\s*$/); }
Update 2: I had not noticed when I wrote the first update above, but poj sent me a CB message proposing a very similar correction. Thanks to poj. Further update: I had also not seen that poj also posted the correction as an answer to your question, so that these updates end up not to be very useful...while (my $line = <$fh_in>) { print $fh_out $line if $line !~ /^\s*$/; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Remove whitespace between lines
by wrkrbeee (Scribe) on Feb 03, 2015 at 18:41 UTC | |
by poj (Abbot) on Feb 03, 2015 at 18:51 UTC | |
by wrkrbeee (Scribe) on Feb 03, 2015 at 18:55 UTC | |
by Marshall (Canon) on Feb 04, 2015 at 01:04 UTC | |
|
Re^2: Remove whitespace between lines
by Anonymous Monk on Feb 03, 2015 at 18:58 UTC |