[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Would like suggestion.



On Mon, 4 Dec 2000 19:10:55 GMT, Bill Becker wrote:

>I have a very large text file with about 90,000 lines in it. A vast majority
>of the lines are blank. (In case anyone is interested, it was created with the
>bookmanager print-to-file command)
>
>My question involves is this: When 3 (or "N") or more blank lines are found,
>delete them. Leaving 2 in their place, and possibly a marker.
>
>Is this easy in PERL?

Yes. Nobody suggested the .. operator yet, so here's one way to use
that.

	while(<>) {
	    if(my $count = (/^$/ .. !/^$/)) {
	        # blank (except for the last one)
	        print if $count < 3 or $count =~ /E/;
	    } else {
	        print;
	    }
	}

In case you're curious: the range operator returns a count, starting
from 1. It is in the format '7E0' in case the right hand side condition
is true (here: test for nonempty line).

-- 
	Bart.

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org