#! /usr/bin/perl # # name: spicnspan # description: Removes tab chars (converts to 4 spaces) & trailing spaces # from code. # developer: Nathan G. Marley # date: 2010Ene19 # # change history: # ======================================================================== # description: change description placeholder # developer: developer name goes here # date: YYYYMmmDD # ======================================================================== use strict; use Data::Dumper; use File::Basename; use Carp; # boilerplate my $progname = basename($0); my $usage = "usage: $progname ..."; # main section foreach my $filename ( @ARGV ) { # slurp file data my $indata = &slurp_file( $filename ); # clean file data my $outdata = &scrub_data( $indata ); # write file data to disk &write_file( $filename, $outdata ); } # subroutines... sub slurp_file() { my $codefile = shift; my $data; if ( ! -f $codefile ) { print STDERR "error: '$codefile' doesn't exist or not a regular file.\n"; } open(IN, "< $codefile") or die "Can't open '$codefile': $!"; { local undef $/; $data = ; } close(IN); return $data; } sub scrub_data() { my $indata = shift; my $outdata = $indata; # strip Windows-style linefeeds $outdata =~ s%\x0d%%g; # convert all tabs to 4 space chars $outdata =~ s%\t% %g; # remove any trailing spaces $outdata =~ s% +\n%\n%g; return $outdata; } sub write_file( $codefile, $outdata ) { my ( $codefile , $outdata ) = (@_)[0,1]; open(OUT, "> $codefile") or die "Can't open '$codefile' for writing: $!"; print OUT $outdata; close(OUT); }