Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!oz.cis.ohio-state.edu!jgreely From: jgreely@oz.cis.ohio-state.edu (J Greely) Newsgroups: comp.lang.perl Subject: Re: Novice Question, Successive Lines Message-ID: Date: 21 Mar 90 10:43:59 GMT References: <13447@cgl.ucsf.EDU> Sender: usenet_news@tut.cis.ohio-state.edu Reply-To: J Greely Distribution: na Organization: Ohio State University Computer and Information Science Lines: 33 In-reply-to: alonso@maxwell.mmwb.ucsf.edu's message of 21 Mar 90 04:55:20 GMT In article <13447@cgl.ucsf.EDU> alonso@maxwell.mmwb.ucsf.edu (Darwin Alonso) writes: >How would one get perl to replace two or more successive blank lines >with one blank line? Whole bunch of possibilities. Here's a relatively straightforward approach: while (<>) { if (/^$/) { $seen++; }else{ print "\n" if $seen; $seen = 0; print; } } print "\n" if $seen; A shorter solution that chews up more memory: undef $/; $_ = <>; s/\n{3,}/\n\n/g; s/^\n{2,}/\n/; print; I can't think of a better solution (shorter and more twisted, natch) at the moment, but I'm sure one of the other fertile minds out there can. -- J Greely (jgreely@cis.ohio-state.edu; osu-cis!jgreely)