1#!/usr/bin/env perl
2
3=head1 NAME
4
5remove_extra_comments.pl
6
7=head1 SYNOPSIS
8
9remove_extra_comments.pl [options] [infile]
10
11=head1 OPTIONS
12
13=over 4
14
15=item B<infile>
16
17Input file to process (uses stdin if not specified)
18
19=item B<--help|-h>
20
21A little help
22
23=item B<--verbose|-v>
24
25Output debug messages (to stderr), repeat for even more output
26
27=back
28
29=head1 DESCRIPTION
30
31Remove any double sets of lines starting ! ******
32E.g. removes the lines
33! ****
34! ****
35These extra lines get created by the fixcomments.pl script because it's not
36always guaranteed that a header will have them at the start and end and this
37it will always add in the header lines.
38
39=cut
40
41use strict;
42use warnings;
43use Pod::Usage qw(pod2usage);
44use Getopt::Long;
45
46my $verbose = 0;
47my $help = 0;
48
49GetOptions(
50    'verbose+' => \$verbose,
51    'help|?' => \$help) or pod2usage(2);
52pod2usage(1) if $help;
53
54sub print_debug {
55    print(STDERR "DEBUG: @_\n") if ($verbose > 0);
56}
57
58
59my $count = 0;
60
61while (my $currline = <>) { # While there are still lines to read
62    # We want to strip out any double sets (i.e. lines next to each other of lines starting ! ****
63    if ($currline =~ m/^!\s+\*+/i) {
64        my $nextline = <>;  	# If we get a match read in the next line
65        while ($nextline eq $currline) {  # Keep reading until we find a different line
66            $count += 1;  # Count up how many lines get stripped out
67            $nextline = <>;
68        }
69        print $currline; # Dump out the ! ** and the next line that is not a duplicate
70        print $nextline;
71    } else {
72        print $currline;  # Print out all the remainder of the file
73    }
74}
75
76print_debug("remove_extra_comments.pl:: removed a total of ", $count, " duplicate comment lines from file", "\n");
77