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

Re: [MacPerl] Would like suggestion.



wpb@jps.net (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? (I know everthing in PERL is easy to a lot of you folks,
>it's just not intuitively obvious to me, yet!)

Yes, it sure is easy:

---------------------------------------
open IN, "file.original" or die $!;
open OUT, ">file.copy"   or die $!;

my $blanks = 0;
while (<IN>) {
  $blanks = (length == 1 ? $blanks + 1 : 0);
  print OUT if $blanks <= 2;
}

close OUT;
close IN;
---------------------------------------


By the way, it's "Perl", not "PERL".  Unless you're yelling. =)

 -Ken
 

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