in reply to How do I remove blank lines from text files?
As an explanation: I had the <IN> in a while loop, to take advantage of the diamond operator's auto-assign-to-$_ feature. This code just makes the assignment explicit.
Thanks, davorg!
This will write a new file with blank lines (where there are two or more newlines together) removed:
Variations on this theme (like whitespace, as noted elsewhere in this thread) would be similar...local $/ = undef; open IN, "<junk" or die "Couldn't open junk: $!"; open OUT, ">fixed" or die "Couldn't open fixed: $!"; ($_ = <IN>) =~ s/\n{2,}/\n/g; print OUT; close IN; close OUT;
Russ
|
---|
Replies are listed 'Best First'. | |
---|---|
RE: RE: How do I remove blank lines from text files?
by perlmonkey (Hermit) on Jul 11, 2000 at 08:29 UTC | |
by Russ (Deacon) on Jul 11, 2000 at 08:37 UTC | |
RE: RE: How do I remove blank lines from text files?
by davorg (Chancellor) on Jul 10, 2000 at 23:32 UTC |