--- "Moore, Larry" <[EMAIL PROTECTED]> wrote: > I want to slurp a file and make multiple blank lines into single blank > lines. Here is my code: > > #! perl -w > use strict; > > my $file = "test.fmt"; > > open (IN, $file) or die; > open (OUT, ">>test.txt"); > > my $text; > > { > local $/; > $text = <IN>; > close IN; > } > > # $text =~ s/\0{2,}/\0\0/mg; # this removes all the blank lines > > # $text =~ s/(^$^$)(^$)+/$1/mg; # also removes all blank lines and > complains > > # $text =~ s/(\n\n)(\n)+/$1/mg; # no improvement here either > > print OUT "$file\n\n$text\n******************"; > close OUT;
I'm not sure what you mean by "blank lines". I would take that to mean that lines that were all whitespace should also be included (e.g., a single tab with three spaces on a line would be a blank line). If so, the following should work: <perl> #! perl -w use strict; my $text = ''; { local $/; $text = <DATA>; } $text =~ s/(?:\n\s*\n)+/\n\n/g; print $text; __DATA__ test asdf test test </perl> Cheers, Curtis "Ovid" Poe ===== "Ovid" on http://www.perlmonks.org/ Someone asked me how to count to 10 in Perl: push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//; shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A __________________________________________________ Do You Yahoo!? Great stuff seeking new owners in Yahoo! Auctions! http://auctions.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]