Hello, 

 

I'm trying to print a tab delimited file based on a colon separated file
matching a key in %hash.  I've attempted a few different things w/ the
colon separated file (splitting it into to variables, making it %hash2)
but I'm not having any luck.   

 

I'm trying to match up a text file, created from an email form, into the
correct tabbed column. The %hash contains all the fields possible that
could come over in the emailed form... the email (text file) only
contains fields that were completed.

 

Text file (comma separated)

 

VendName: vendors name

VendEmail: [EMAIL PROTECTED]

VendPhone: 555-555-5555

VendWeb: www.example.com

CSManName: Customer Service Name 

 

%hash - values all = 1

 

VendName

VendMailAdd 

VendCSZ

VendEmail

VendPhone

VendFax

VendWeb

MinorityNo

CSManName

 

 

Below is what I have so far.

 

#!/usr/bin/perl 

 

use strict;

use warnings;

 

my $file = "c:/brian/AX/vendor/vendor_fields.txt"; # testing... works!

    open(FILE, $file) or die "Can't open the $file: $!\n";

 

my $new_ax = "c:/brian/AX/vendor/vendor_fields_new.txt";

    open (NEW, "> $new_ax") or die "Can't open $new_ax:$!\n";

 

my %hash; 

while(<FILE>){ 

  chomp $_;                        #remove the newline 

  my($key,$value) = split(/\t/,$_); #split by tab

  $hash{$key} = $value;            #assign the value here

 

my $email = "c:/brian/AX/vendor/email_file_new.txt"; 

    open(EMAIL, $email) or die "Can't open the $email: $!\n";

 

 

while(<EMAIL>){

    chomp $_;

    my($emailField, $emailValue) = split(/\:/,$_);

    if ($emailField eq $key) { 

    print NEW "$emailValue \t";

    } else {

    print NEW "blank \t";

              }        

                }

   

              }

 

  

   

Any help would be greatly apprecieated.

 

Thanks!

 

Brian Volk

 

           

 

Reply via email to