in reply to RE: How do I remove blank lines from text files?
in thread How do I remove blank lines from text files?

Just to nitpick a tiny bit, I want to warn about your modification to $/.

By doing things the way to did, you are setting yourself up for crazy-ass bugs. You properly localize the variable, but the scope of the localization is way too broad.

I suggest getting in the habit of anonymous blocks every time you localize a global variable. Like This:
open OUT, ">fixed" or die "Couldn't open fixed: $!"; open IN, "<junk" or die "Couldn't open junk: $!"; { local $/ = undef; ($_ = <IN>) =~ s/\n{2,}/\n/g; print OUT; } close IN; close OUT;
This way you properly limit the scope of local $/ to just the lines you need it. And wont accidentilly screw yourself up later.

Replies are listed 'Best First'.
RE:(3) remove blank lines? (localizing block for $/)
by Russ (Deacon) on Jul 11, 2000 at 08:37 UTC
    Good point. I should have included that in my snippet.

    Russ
    Brainbench 'Most Valuable Professional' for Perl