#!/usr/bin/perl
# Take all groups of leading 4 spaces, and convert to a tab
# usage: ./space2tab.pl filename [filename2 ...]

foreach $file (@ARGV) {
	print "File: $file...";

	`cp $file $file.bak`;

	open (IFD, "<$file.bak");
	open (OFD, ">$file");

	$numlines = 0;
	$numchanges = 0;
	while (<IFD>) {
		while($temp = ($_ =~ s/^([\t]*)    /$1\t/g)) { $numchanges += $temp; }
		$numlines++;
		print OFD "$_";
	}
	close IFD;
	close OFD;
	print "Processed $numlines lines, made $numchanges changes.\n";
}
