#!/Perl
# stripleft.pl
# AIM: Input a text file, and strip a number of columns from
# the left side of the file, and output the results
# geoff mclane - nov, 2006

print "$0 ...Hello, World...\n";

##my $def_in = 'c:\dtemp\ip.h';
my $def_in = 'c:\dtemp\tempns.txt';
my $def_wid = 6;
my $def_out = 'temp.'.$0.'.txt';

my $in_file = $def_in;
my $width = $def_wid;
my $out_file = $def_out;
my @newlns = ();
my @lines = ();
my $lcnt = 0;
my $line = '';
my $llen = 0;
my $off = 0;
my $nl = '';

if (@ARGV) {
	$in_file = pop @ARGV;
}
if (@ARGV) {
	$width = pop @ARGV;
}
if (@ARGV) {
	$out_file = pop @ARGV;
}

print "Processing $in_file, width $width, output to $out_file ...\n";

open INF, "<$in_file" or die "ERROR: Unable to open $in_file ... $! ...\n";
@lines = <INF>;
close INF;
$lcnt = scalar @lines;
print "Got $lcnt to process ...\n";
foreach $line (@lines) {
	chomp $line;
	$llen = length($line);
	if ($llen > $width) {
		$off = $width;
	} else {
		$off = $llen;
	}
	$nl = substr($line, $off);
	push(@newlns, $nl);
}

open OUTF, ">$out_file" or die "ERROR: Unable to open out file $out_file ... $! ...\n";
foreach $line (@newlns) {
	print OUTF "$line\n";
}
close OUTF;
$lcnt = scalar @newlns;
print "Written $lcnt lines to $out_file ...\n";
system($out_file);

# eof - stripleft.pl