Skip to content

Instantly share code, notes, and snippets.

@FooBarrior
Created August 9, 2011 02:29
Show Gist options
  • Save FooBarrior/1133290 to your computer and use it in GitHub Desktop.
Save FooBarrior/1133290 to your computer and use it in GitHub Desktop.
reset all incorrect spaces to tabs. currently buggy
#!/usr/bin/perl
use warnings;
use strict;
sub write_file{
my $fname = $_[0];
print "%%%%% WANNA $fname?\n";
open my $f, "< $fname";
my @file = <$f>;
close $f and return 1 unless grep m/^\ \ /, @file;
print LOG "\n<<<<<<<<<<<<<<<<<<<<<<<<\n$fname\n>>>>>>>>>>>>>>>>>>>>>>>> :\n";
foreach my $i(0..$#file-1){
$file[$i] =~ s/ /\t/g and print LOG "$i:$file[$i]";
}
close $f;
open $f, '>', $fname;
print $f @file;
close $f;
}
sub walk_dir{
my $path = shift;
print "~~~~walking into $path~~~~\n";
opendir (my $dir, $path) or die;
while(my $file = readdir($dir)){
#print "\n\nwhois $file?\n\n";
next if $file =~ m!^\.+|.*\.(pyc|jpe?g|png|bmp)!;
$file = $path."/$file";
print "$file\n" if -d $file;
walk_dir($file) and print "~~~~got back~~~~\n" and next if -d $file;
print ">>>>>>BAD $file" and next if !-T $file;
write_file($file);
}
1;
}
my $log = $_[1] || 'cleantabs.log';
open LOG, '>', $log;
walk_dir shift || '.';
close LOG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment