Untitled
public text v1 · immutable#!/usr/bin/perl -w
use strict;
my $file = "";
my $nspace = 4;
($ARGV[0] && ($file = $ARGV[0])) ||
die "no filename given";
$ARGV[1] && ($nspace = $ARGV[1]);
print "converting $file: $nspace spaces -> 1 tab\n";
unless (-r $file) {
die "can't open $file: $!";
}
open(IN, "< " .$file);
open(OUT, ">.tmp_" . $file);
foreach (<IN>) {
# s/\r//;
s/\s{$nspace}/\t/g;
s/[\t ]*([\r\n]*)$/$1/;
print OUT;
}
close IN;
close OUT;