stripleft.pl to HTML.

index -|- end

Generated: Tue Feb 2 17:54:57 2010 from stripleft.pl 2009/05/21 1.7 KB.

#!/Perl
# stripleft.pl - stip columns
# AIM: Input a text file, and strip a number of columns from
# the left side of the file, and output the results
# 14/05/2009 - update
# geoff mclane - nov, 2006
print "$0 ...Hello, World...\n";
##my $def_in = 'c:\dtemp\ip.h';
my $def_in = "C:\\GTools\\ConApps\\testap1\\temp1.txt";
#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 = '';
my $def_in_file = "C:\\GTools\\ConApps\\testap1\\temp1.txt";
my $def_out_file = "tempstrip.txt";
if (@ARGV) {
   $in_file = pop @ARGV;
} else {
   $in_file = $def_in_file;
}
if (@ARGV) {
   $width = pop @ARGV;
} else {
   $width = $def_wid;
}
if (@ARGV) {
   $out_file = pop @ARGV;
} else {
   $out_file = $def_out_file;
}
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;
   #print "$line\n";
   $llen = length($line);
   if ($llen > $width) {
      $off = $width;
   } else {
      $off = $llen;
   }
   $nl = substr($line, $off);
   #print "$nl\n";
   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

index -|- top

checked by tidy  Valid HTML 4.01 Transitional