Permalink
Browse files

Init

  • Loading branch information...
0 parents commit 878da0933f878970fe57b7e65ae78fb0cc12900f @dermesser committed Apr 11, 2012
Showing with 70 additions and 0 deletions.
  1. +9 −0 README
  2. +13 −0 example.txt
  3. +13 −0 use_this_example.txt
  4. +35 −0 whitespace.pl
@@ -0,0 +1,9 @@
+whitespace.pl removes whitespace errors in files.
+
+A whitespace error is:
+ - tabs in an (else) empty line
+ - spaces in an empty line
+ - or both
+Whitespace errors are created when working with a auto-indent
+text editor like vim or some IDEs. This script removes the errors from
+the file. The clean file is written back to the original file.
@@ -0,0 +1,13 @@
+Hello,
+
+World.
+
+This file
+
+contains whitespace errors.
+
+That is if
+
+there's a tab or some spaces
+
+in a line which is actually empty.
@@ -0,0 +1,13 @@
+Hello,
+
+World.
+
+This file
+
+contains whitespace errors.
+
+That is if
+
+there's a tab or some spaces
+
+in a line which is actually empty.
@@ -0,0 +1,35 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use utf8;
+use File::Copy;
+
+die("Usage: whitespace.pl <FILE>\n") if scalar @ARGV != 1;
+
+open(my $tempfile,">",".white_tmp");
+open(my $file,"<",$ARGV[0]);
+
+my $pat = qr/^(\t| )+$/;
+my $i = 0;
+
+while ( my $line = <$file> )
+{
+ $i++;
+
+ if ( $line =~ $pat )
+ {
+ #print $i." ".$line;
+ print $tempfile "\n";
+ } else
+ {
+ print $tempfile $line;
+ }
+}
+
+close($file);
+close($tempfile);
+
+copy(".white_tmp",$ARGV[0]);
+
+unlink(".white_tmp");

0 comments on commit 878da09

Please sign in to comment.