1#!/usr/bin/env perl 2 3=head1 NAME 4 5remove_double_ampersands.pl 6 7=head1 SYNOPSIS 8 9remove_double_ampersands.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 31Want to locate any lines where we have an ampersand at the end of a line followed 32by an ampersand at the start of the next line as these causes the fixcomments.pl 33script to break as it uses the ampersand to decide whether there is more data to 34read. 35An example would be (from cp_lbfgs.F): 36 SUBROUTINE setulb(n, m, x, l, u, nbd, f, g, factr, pgtol, wa, iwa,& 37 & task, iprint, csave, lsave, isave, dsave) 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; 60my $countampend = 0; 61my $countampstart = 0; 62my $currline = <>; # First time we enter the loop we need to read in two lines, read the first now 63my $linesread = 1; 64 65while (my $nextline=<>) { # While there are still lines to read, either from STDIN or the files specified 66 $linesread += 1; 67 68 if ( ($currline =~ m/&\s*$/i) && ($nextline =~ m/^\s*&\s*\w+/i) ) { 69 $nextline =~ s/&/ /; 70 print_debug("remove_double_ampersands.pl:: CURRLINE is ", $currline); 71 print_debug("remove_double_ampersands.pl:: NEXTLINE is ", $nextline); 72 $count += 1; 73 } 74 75 print $currline; # Write all lines except the last one - initial & replaced with space 76 $currline = $nextline 77} 78 79print $currline; # Write the last line (unaltered) 80 81print_debug("remove_double_ampersand.pl:: ", $linesread, " lines read in, found a total of ", $count, " lines with the double ampersand issue in file", " \n"); 82