Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by perlmonkey (Hermit)
on Jul 11, 2000 at 08:29 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://21915]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-20 08:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found