| author | Nicholas Hastings <skamonkey@gmail.com> |
| Sun Jul 15 12:31:06 2012 -0400 (2012-07-15) | |
| changeset 3579 | 6d730190a3e4 |
| parent 2762 | d2d467bf1b5a |
| permissions | -rwxr-xr-x |
1 #!/usr/bin/perl
3 # This is a script for removing trailing whitespace from lines in files that
4 # are listed on the command line.
6 # This subroutine does the work for one file.
8 sub detrail {
9 my($file) = $_[0];
10 my($changed) = 0;
11 open(IN, "$file") || die "Can't open $file for input";
12 @lines = <IN>;
13 close(IN);
14 foreach (@lines)
15 {
16 if (/\s+\n$/)
17 {
18 s/\s+\n$/\n/;
19 $changed = 1;
20 }
21 }
22 if ($changed)
23 {
24 open(OUT, ">$file") || die "Can't open $file for output";
25 print OUT @lines;
26 close(OUT);
27 }
28 }
30 # This is the main program
32 $, = ""; # Output field separator
33 for ($i = 0; $i < @ARGV; $i++) { &detrail($ARGV[$i]); }
35 # End