diff options
author | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2016-07-13 21:24:43 +0100 |
---|---|---|
committer | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2016-07-13 21:24:43 +0100 |
commit | cba4af1b7643b0da036ff78fd152f74a906c4e97 (patch) | |
tree | 84f90cc1a9542b2f374932b04ea0752eabbd3741 /Detrail |
Commit upstream pcre-8.39.tar.bz2
Diffstat (limited to 'Detrail')
-rwxr-xr-x | Detrail | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -0,0 +1,35 @@ +#!/usr/bin/perl + +# This is a script for removing trailing whitespace from lines in files that +# are listed on the command line. + +# This subroutine does the work for one file. + +sub detrail { +my($file) = $_[0]; +my($changed) = 0; +open(IN, "$file") || die "Can't open $file for input"; +@lines = <IN>; +close(IN); +foreach (@lines) + { + if (/\s+\n$/) + { + s/\s+\n$/\n/; + $changed = 1; + } + } +if ($changed) + { + open(OUT, ">$file") || die "Can't open $file for output"; + print OUT @lines; + close(OUT); + } +} + +# This is the main program + +$, = ""; # Output field separator +for ($i = 0; $i < @ARGV; $i++) { &detrail($ARGV[$i]); } + +# End |