#!/usr/its/bin/perl # Strip.pl # Written by Andy Ehlert # This perl utility removes the spaces between words # in a text file. It can accept arguments from the # command line, or from within the program itself. # Simply type strip.pl , or just strip.pl. # It will write to a file called .stp. # # # # This allows the program to be run from the command line. # indictated will be stripped of all spaces. # Simply type strip.pl , and the file will be # striped of spaces between words. if ($ARGV[0]){ $file_name= $ARGV[0] } # Otherwise, the program will prompt the user for the name # of the file that they wish to be manipulated. else { print "Enter the name of the file to strip of spaces: "; $file_name = ; chomp($file_name); } # This code removes extentions beyond a period and replaces # it with a .stp, ie. test.txt would become test.stp. This # is to reflect that the new file is different than the file # that was entered. open (IN, $file_name) || die "Can't open file for input!"; $_ = $file_name; # This checks to see if there is a period in the name of the file. # If there is, it replaces everything after the period with the # extention .stp. Otherwise it just adds the .stp to the end of # the file indicated. if(s/\..*/\.stp/) { $file_name = $_; open(OUT, "> $file_name"); } else { open(OUT, "> $file_name.stp"); } # This while loop proceeds through the file until the end of # file is detected. For each line that it finds in the file # the program strips out all spaces, and writes the changed # line to the new file. while() { chomp; s/ //g; print OUT "$_\n"; }