blob: 1c5c7e9cae1b96e20e53dca4fb09d88f7d522862 [file] [log] [blame]
Nick Kralevichf73ff172014-09-27 12:41:49 -07001#!/usr/bin/perl
2
3# This is a script for removing trailing whitespace from lines in files that
4# are listed on the command line.
5
6# This subroutine does the work for one file.
7
8sub detrail {
9my($file) = $_[0];
10my($changed) = 0;
11open(IN, "$file") || die "Can't open $file for input";
12@lines = <IN>;
13close(IN);
14foreach (@lines)
15 {
16 if (/\s+\n$/)
17 {
18 s/\s+\n$/\n/;
19 $changed = 1;
20 }
21 }
22if ($changed)
23 {
24 open(OUT, ">$file") || die "Can't open $file for output";
25 print OUT @lines;
26 close(OUT);
27 }
28}
29
30# This is the main program
31
32$, = ""; # Output field separator
33for ($i = 0; $i < @ARGV; $i++) { &detrail($ARGV[$i]); }
34
35# End