I'm back to dealing with the main issue of a badly formatted file being
brought down from an archaic system and needing to be cleaned up before
being passed to another user or a database table.  I have the code
below, which pulls the whole file in and parse it line by line.  That
problem is still that when the stuff is done parsing the file, the file
still has a ton of white spaces left in it.

What I would like to do is when I first open the file (another piece of
this massive script) is tell it to just run a sub program on each piece
that does the same thing as the stuff below, unfortunately I am not sure
of the way to do this.

This piece I DO have:
sub cleanup{

use strict;

my $file = "info/bad.sql";
my $newfile = "info/inventory.sql";
my $line;

        open (OLDFILE, "< $file");
        open (NEWFILE, "> $newfile");
        while ($line = <OLDFILE>)  {
                $line =~ s/^ //mg;
                $line =~ s/ $//mg;
                $line =~ s/\t/|/mg;
                $line =~ s/\s+/ /mg;
                $line =~ s/^\s*//mg;
                $line =~ s/\s*$//mg;
                $line =~ s/\s*$//mg;
###  The following lines mod the files to reflect inches and feet
                $line =~ s/(?<=\d)"/in. /mg;
                $line =~ s/(?<=\d)'/ft. /mg;
                $line =~ s/^\s+//mg;
                $line =~ s/\s+$//mg;
#               $line =~ s/\s*\|\s*//mg;
###             $line =~ s/ |/|/mg;
###             $line =~ s/| /|/mg;             

                print NEWFILE "$line\n";
        }
        close OLDFILE;
        close NEWFILE;
        
  print "$newfile has now been created\n";
}

The first pass of the code which piece of the array of data into another
location further back in the file:
sub MySQL_id_data
{
 $database_file = "info/salesa1";
 open(INF,$database_file) or dienice("Can't open $database_file: $!
\n");
 @grok = <INF>;
 close(INF);
 $file1 = "info/salesa1-data";
 open (FILE, ">$file1") || die "Can't write to $file1 : error $!\n";
 $inv = 1;
 
 foreach $i (@grok)
 {
  chomp($i);
 
($item_num,$item_desc,$b1,$b2,$b3,$b4,$cc,$vn,$qoh,$qc,$qor,$bc,$sc,$yp)
= split(/\|/,$i);
   print FILE
"$inv|$item_num|$item_desc|$b1|$b2|$b3|$b4|$cc|$vn|$qoh|$qc|$qor|$bc|$it
em_num|$sc|$yp\n";
   $inv++;
 }
 close FILE;
}


HELP!!

Thanks,
Robert


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to