All pastes #521826 Raw Edit

Untitled

public text v1 · immutable
#521826 ·published 2007-05-30 08:45 UTC
rendered paste body
#!/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;