Hi all, I am trying to parse a file with the following script:
#!/usr/bin/perl use strict; open (INFILE, "datafile.txt") || die "$!"; my @lines = <INFILE>; my $employeeNumber; my $mail; my $envalue; my $mailvalue; foreach (@lines) { chomp; if (/^employeeNumber/) { ($employeeNumber,$envalue) = split / /,$_; print "$employeeNumber $envalue\n"; } elsif (/^mail/) { ($mail,$mailvalue) = split / /,$_; print "$mail $mailvalue\n"; } } The print statements are for testing and to see what the program is actually parsing. I need to pull the employeeNumber and Mail from the file. This is working fine but there are a few roadblocks that I am hitting. 1. Look at the sample file that is being used for the data. You will see that there are sections that have both employeeNumber and mail and some that have one or the other. 2. I need to have the output as such: 101157 [EMAIL PROTECTED] or [EMAIL PROTECTED] or 101157 As you can see, if there is an entry without the employeeNumber and just the email, I need to print out just the email in the second column and vice versa if there is just the employeeNumber and no email or if there are both, print both as shown. Here is the sample data file: ################### SNIP #################### dn: Cn:Rjwoll,ou=USR,ou,B008,ou=LIV,o=ROUSH Changetype: add employeeNumber: 100069 mail: [EMAIL PROTECTED] dn: Cn:Rjwoll,ou=USR,ou,B008,ou=LIV,o=ROUSH dn: Cn:Rjwoll,ou=USR,ou,B008,ou=LIV,o=ROUSH dn: Cn:Rjwoll,ou=USR,ou,B008,ou=LIV,o=ROUSH dn: Cn:mtdean,ou=USR,ou,B008,ou=LIV,o=ROUSH Changetype: add employeeNumber: 203069 mail: [EMAIL PROTECTED] dn: Cn:cashar,ou=USR,ou,B008,ou=LIV,o=ROUSH Changetype: add employeeNumber: 101157 dn: Cn:Rjwoll,ou=USR,ou,B008,ou=LIV,o=ROUSH Changetype: add employeeNumber: 000057 dn: Cn:cashar,ou=USR,ou,B008,ou=LIV,o=ROUSH Changetype: add mail: [EMAIL PROTECTED] Thanks, Craig _______________________________________________ Perl-Unix-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs