Here's what I have, and I am sure there is a better way to do this...

The problem I am getting is checking to see if one field matches the city,
and if it does keeping it the same, however if it does not it needs to have
a "1-" added to the front of that field...

<-- CODE -->
#!/usr/bin/perl -w

#####
# 
# Main Functions of the script, makes calls to all of the subscripts
performing the functions.
# Also creates pretty output for everyone to check out.  This script is
designed to run after WGEN has been run.
#
#####

no warnings qw(uninitialized);

$content_type   = "Content-Type: text/html\n\n";

print <<ENDPAGE;
[EMAIL PROTECTED] 
<html>
<head>
        <title>Customer Parsing Form</title>
<body bgcolor="white" text="black"> 
<BR>
<center> CUSTOMER FILE DOWNLOAD AND CONFIGURE</center>
<HR>
<BR>
This will download and create the files onto the Intranet from Stanpak. 
Login to Stanpak FIRST and run ROBERT and ROBERT2 from *QICLOOK to create
the files this script needs to handle the rest of this process.<BR>
ENDPAGE
print "Now getting the files from the server (salesa*)<BR><HR>";
#&get_files;
print "<BR><HR><BR><font +2>IF you have done the *QICLOOK report (ROBERTC)
then the files will be there for the server to download.  Once those files
are there and downloaded this script will get the files and put them into
the flat files for inventory and *** items.</font><BR>";
&cleanup;
print <<ENDPAGE2;
This script has finished running and ALL pages should now be updated.
</body>
</html>
ENDPAGE2



sub cleanup{

use strict;
use warnings;
my (@fields, $lng);

opendir INDIR , "/home/web/sales/info/test" or die "Can't open dir with
before files:$!";
#$infile = custs1;

foreach my $infile (grep {!/^\./} readdir INDIR) {
#read all the files in your home/sql dir
#read only files that do not start with a .
  my ($i,$rec, $tmptxt);

  open INFILE, "</home/web/sales/info/test/$infile" or die "Can't open
$infile: $!";
  open OUTFILE, ">/home/multifax/everyone" or die "Can't open ${infile}.out
at home: $!";
  open OUTFILE1, ">/home/multifax/pack-fishbait" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE2, ">/home/multifax/pack-food" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE3, ">/home/multifax/pack-ice_cream" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE4, ">/home/multifax/pack-other" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE5, ">/home/multifax/auto" or die "Can't open ${infile}.out at
home: $!";
  open OUTFILE6, ">/home/multifax/barsupplies" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE7, ">/home/multifax/building" or die "Can't open ${infile}.out
at home: $!";
  open OUTFILE8, ">/home/multifax/candy" or die "Can't open ${infile}.out at
home: $!";
  open OUTFILE9, ">/home/multifax/candy2" or die "Can't open ${infile}.out
at home: $!";
  open OUTFILE10, ">/home/multifax/caterer" or die "Can't open ${infile}.out
at home: $!";
  open OUTFILE11, ">/home/multifax/pack-misc" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE12, ">/home/multifax/coffee" or die "Can't open ${infile}.out
at home: $!";
  open OUTFILE13, ">/home/multifax/concessions" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE14, ">/home/multifax/dairy" or die "Can't open ${infile}.out
at home: $!";
  open OUTFILE15, ">/home/multifax/convenience" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE16, ">/home/multifax/fruit_produce" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE17, ">/home/multifax/hotel" or die "Can't open ${infile}.out
at home: $!";
  open OUTFILE18, ">/home/multifax/instit_regional" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE19, ">/home/multifax/instit_indep" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE20, ">/home/multifax/instit_ethnic" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE21, ">/home/multifax/indust" or die "Can't open ${infile}.out
at home: $!";
  open OUTFILE22, ">/home/multifax/janitorial" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE23, ">/home/multifax/jan_cleaning" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE24, ">/home/multifax/office" or die "Can't open ${infile}.out
at home: $!";
  open OUTFILE25, ">/home/multifax/paper_multi" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE26, ">/home/multifax/paper_food" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE27, ">/home/multifax/paper_indep" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE28, ">/home/multifax/restaurant_supply" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE29, ">/home/multifax/vending-regional" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE30, ">/home/multifax/vending-indep" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE31, ">/home/multifax/all_other" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE32, ">/home/multifax/unclassified" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE33, ">/home/multifax/cash_grocer" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE34, ">/home/multifax/cash_thomas-howard-green" or die "Can't
open ${infile}.out at home: $!";
  open OUTFILE35, ">/home/multifax/cash_thomas-howard-spartan" or die "Can't
open ${infile}.out at home: $!";
  open OUTFILE36, ">/home/multifax/grocery" or die "Can't open ${infile}.out
at home: $!";
  open OUTFILE37, ">/home/multifax/hardware" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE38, ">/home/multifax/rental" or die "Can't open ${infile}.out
at home: $!";
  open OUTFILE39, ">/home/multifax/paper_party-indep" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE40, ">/home/multifax/paper_party_store" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE41, ">/home/multifax/empty_sic" or die "Can't open
${infile}.out at home: $!";
  open OUTFILE42, ">/home/web/sales/cust-parsed" or die "Can't open
${infile}.out at home: $!";


  
  while (<INFILE>) {
   $rec++;
   $i++;
   chomp;
   @fields = split /\s*\|\s*/, $_;
   $fields[0] =~ s/^\s+//;
   $fields[1] =~ s/ /_/g;

   if ($fields[4] == "RALEIGH"){ 
    $tmptxt = $fields[10];
   }
   elsif ($fields[4] == "CARY"){ 
    $tmptxt = $fields[10];
   }
   elsif ($fields[4] == "DURHAM"){ 
    $tmptxt = $fields[10];
   }
   elsif ($fields[4] == "APEX"){ 
    $tmptxt = $fields[10];
   }
   elsif ($fields[4] == "MORRISVILLE"){ 
    $tmptxt = $fields[10];
   }
   elsif ($fields[4] == "Holly Springs"){ 
    $tmptxt = $fields[10];
   }
   elsif ($fields[4] == "FUQUAY-VARINA"){ 
    $tmptxt = $fields[10];
   }
   elsif ($fields[4] == "FUQUAY VARINA"){ 
    $tmptxt = $fields[10];
   }
   elsif ($fields[4] == "FUQUAY-VARINA"){ 
    $tmptxt = $fields[10];
   }
   else {
    $tmptxt = "1-$fields[10]";
#    $tmptxt .= $fields[10];
   }    

   #there is probably a way to get rid of the trailing spaces in the first
entry using split,I just couldnt think of any.

#   $lng = @fields unless $lng; #set $lng for first record
#   print "The following record: $i has ", scalar @fields, " fields as
compared to $lng fields in the first record!  Skip. : $_\n" and next unless
$lng == @fields;
#   poor quality control of your input data: check if all reords have the
same number of fields or skip and print record otherwise.
#   i++;

   print OUTFILE42 "$_|" foreach (@fields);
   print OUTFILE "[EMAIL PROTECTED]"; #your trailing ID
#   print OUTFILE42 "$_|" foreach (@fields);

   if ($fields[11] == 102){ 
    print OUTFILE1 "[EMAIL PROTECTED]"; #your trailing ID
   }
   elsif ($fields[11] == 104){ 
    print OUTFILE2 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 106){ 
    print OUTFILE3 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 108){ 
    print OUTFILE4 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 109){ 
    print OUTFILE5 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 110){ 
    print OUTFILE6 "[EMAIL PROTECTED]"; #your trailing ID
   }
   elsif ($fields[11] == 112){ 
    print OUTFILE7 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 113){ 
    print OUTFILE8 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 114){ 
    print OUTFILE9 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 116){ 
    print OUTFILE10 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 118){ 
    print OUTFILE11 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 119){ 
    print OUTFILE12 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 120){ 
    print OUTFILE13 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 122){ 
    print OUTFILE14 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 123){ 
    print OUTFILE15 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 124){ 
    print OUTFILE16 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 127){ 
    print OUTFILE17 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 129){ 
    print OUTFILE18 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 130){ 
    print OUTFILE19 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 131){ 
    print OUTFILE20 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 132){ 
    print OUTFILE21 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 133){ 
    print OUTFILE22 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 134){ 
    print OUTFILE23 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 139){ 
    print OUTFILE24 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 149){ 
    print OUTFILE25 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 151){ 
    print OUTFILE26 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 153){ 
    print OUTFILE27 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 161){ 
    print OUTFILE28 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 170){ 
    print OUTFILE29 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 173){ 
    print OUTFILE30 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 176){ 
    print OUTFILE31 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 177){ 
    print OUTFILE32 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 182){ 
    print OUTFILE33 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 183){ 
    print OUTFILE34 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 185){ 
    print OUTFILE35 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 187){ 
    print OUTFILE36 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 189){ 
    print OUTFILE37 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 191){ 
    print OUTFILE38 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 193){ 
    print OUTFILE39 "[EMAIL PROTECTED]"; #your trailing ID
   }

   elsif ($fields[11] == 196){ 
    print OUTFILE40 "[EMAIL PROTECTED]"; #your trailing ID
   }

   else { 
    print OUTFILE41 "[EMAIL PROTECTED]"; #your trailing ID
   }


  }
  close INFILE;
  close OUTFILE;
  close OUTFILE1;
  close OUTFILE2;
  close OUTFILE3;
  close OUTFILE4;
  close OUTFILE5;
  close OUTFILE6;
  close OUTFILE7;
  close OUTFILE8;
  close OUTFILE9;
  close OUTFILE10;
  close OUTFILE11;
  close OUTFILE12;
  close OUTFILE13;
  close OUTFILE14;
  close OUTFILE15;
  close OUTFILE16;
  close OUTFILE17;
  close OUTFILE18;
  close OUTFILE19;
  close OUTFILE20;
  close OUTFILE21;
  close OUTFILE22;
  close OUTFILE23;
  close OUTFILE24;
  close OUTFILE25;
  close OUTFILE26;
  close OUTFILE27;
  close OUTFILE28;
  close OUTFILE29;
  close OUTFILE30;
  close OUTFILE31;
  close OUTFILE32;
  close OUTFILE33;
  close OUTFILE34;
  close OUTFILE35;
  close OUTFILE36;
  close OUTFILE37;
  close OUTFILE38;
  close OUTFILE39;
  close OUTFILE40;
  close OUTFILE41;
  close OUTFILE42;
  print "Read $rec records from /home/web/sales/info/test/$infile and
printed $i into /home/web/sales/info/test/${infile}.out\n"; } closedir
INDIR;
}

--
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