OK. I've been over all your code. Here is the way I would do this. N.B I've not checked for errors or typos. It's commented to explain the changes.
Basically instead of having to grep the second file for every iteration of the foreach loop, you initialize a hash with the data from the second file. This is in the format name=>email. This allows you to do a fast lookup for the users email address when you are processing the input.txt file. HTH John -- Code follows -- open (LIST1, "<input.txt") or die "Can't open input.txt: $!"; # Always check for errors when opening a filehandle open (MAILLIST, "<nt-smtp.txt") or die "Can't open nt-smtp.txt: $!"; my %mail_lookup; # Loop over each line in the MAILLIST file. This doesn't require having to slurp the file into memory. foreach (<MAILLIST>) { # Split the element into name and mail parts my ($name, $mail) = split(/,/); # Store the data in the mail_lookup hash. Use the name as the key and the mail address as the data $mail_lookup{$name} = $mail; } close MAILLIST; # Close the MAILLIST filehandle. It's contents have been dealt with while(<LIST1>) { # Split the name from the .txt extension eg. conorl my ($Name) = split(/\./, $_); # Use () around variable being assigned. This turns the returned array from split and stores the first element as the $Name scalar # read the name # $Name=$data[0]; This line is not needed, all done in one step above # print the name so we know what is happening print "$Name\n"; # You don't need to use printf unless you are formatting the output. It just adds overhead in this instance. # The below three steps aren't needed, they were perfomred in the foreach loop above # Grep the name from the second file, outputting result to @data1 # @data1=grep /$Name/i, @maillist; # print the @data1 so we know wheat is happening again # printf "DATA1 @data1"; # split @data1, to isolate the e-mail address from the name eg. [EMAIL PROTECTED] # @emaildata = split(/,/, @data1); # print the e-mail address, NOT. This prints an integer, I am not sure why. HELP this where it goes pear-shaped. print "emaildata is $mail_lookup{$Name}"; # Lookup the mail address from the hash with the keyname $Name. } -- Code Ends -- -----Original Message----- From: Conor Lillis [mailto:[EMAIL PROTECTED]] Sent: 11 January 2002 13:08 To: PERL Beginners (E-mail); Perl-Win32-Users (E-mail) Subject: Data manipulation problem Hi all, hopefully someone can help me with this, I will describe my problem as best as I can. I am opening 2 files, one has a list of NT account names, The 2nd has a list of NT account names & e-mail addresses. I am trying to match an NT account name from the first list to an e-mail address in the second file by NT account name. My comments are to explain what my bumbling logic is, can someone tell me how I might try and pull the e-mail address from the @emaildata ? --------------script starts ----------------------------------------------------- open (LIST1, "<input.txt"); open (MAILLIST, "<nt-smtp.txt"); @maillist=<MAILLIST>; while(<LIST1>) { # Split the name from the .txt extension eg. conorl @data = split(/\./, $_); # read the name $Name=$data[0]; # print the name so we know what is happening printf "$Name\n"; # Grep the name from the second file, outputting result to @data1 @data1=grep /$Name/i, @maillist; # print the @data1 so we know wheat is happening again printf "DATA1 @data1"; # split @data1, to isolate the e-mail address from the name eg. [EMAIL PROTECTED] @emaildata = split(/,/, @data1); # print the e-mail address, NOT. This prints an integer, I am not sure why. HELP this where it goes pear-shaped. printf "emaildata is @emaildata[0]"; } ----------script ends------------------------------------------------------------ sample input.txt data conorl.txt sample nt-smtp.txt data conorl,[EMAIL PROTECTED] The information in this email is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised.if you are not the intended recipient, any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful. Please note that any views, opinions or advice contained in this email are those of the sending individual and not necessarily those of the firm. It is possible for data transmitted by e-mail to be deliberately or accidentally corrupted or intercepted. For this reason, where the communication is by e-mail, J&E Davy does not accept any responsibility for any breach of confidence which may arise from the use of this medium. If you have received this e-mail in error please notify us immediately at mailto:[EMAIL PROTECTED] and delete this e-mail from your system. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------Confidentiality--------------------------. This E-mail is confidential. It should not be read, copied, disclosed or used by any person other than the intended recipient. Unauthorised use, disclosure or copying by whatever medium is strictly prohibited and may be unlawful. If you have received this E-mail in error please contact the sender immediately and delete the E-mail from your system. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]