> -----Original Message----- > From: Brian Volk [mailto:[EMAIL PROTECTED] > Sent: Wednesday, February 28, 2007 1:34 PM > To: beginners@perl.org > Subject: print if variable matches key > > 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. > > > [Brian Volk] Sorry to respond to my own post... but I think I'm getting closer... The file is printing okay...I just need to know how to print a tab if the $emailField is not in <EMAIL> ...I guess that is the tricky part. :-) I should probably sort to keep the same field order... [Brian Volk]
my $email = "c:/brian/AX/vendor/email_file_new_less.txt"; open(EMAIL, $email) or die "Can't open the $email: $!\n"; while(<EMAIL>){ chomp $_; my($emailField, $emailValue) = split(/\:/,$_); if (exists $hash{$emailField}) { print NEW "$emailValue \t"; } else { print NEW "blank \t"; } } Any pointers would be greatly appreciated. Thanks! Brian -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/