Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

RE: RE: How do I remove blank lines from text files?

by perlmonkey (Hermit)
on Jul 11, 2000 at 08:29 UTC ( #21915=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://21915]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2020-10-21 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (212 votes). Check out past polls.

    Notices?