R. Joseph Newton wrote:

>Jan Eden wrote:
>
>>Hi,
>>
>>[EMAIL PROTECTED] wrote:
>>
>>>I have a text file with a records like:
>>>
>>>smith, James, Dr., 115 Fourth Street, Chicago, IL, 32012, $20.00:
>>>[EMAIL PROTECTED]
>>>
>>>and another text file with placeholders like:
>>>
>>>Hello $last_name, $first_name:
>>>
>>>I want to read the first textfile and update the second one.
>>>
>>>Any ideas!
>>
>>This is a very general question. Have you already tried something?
>>Have your read an Introduction to Perl (O'Reilly's "Learning Perl"
>>is highly recommended)?
>>
>>Basically, what you have is a data file and a template file. You
>>should open the data file and read the data into a hash (using
>>pattern matching), then merge the hash and the template file
>>(replacing your placeholders), putting out a scalar variable for
>>each set of data.
>
>I would do it the other way around.  I am guessing here that the OP
>wants to use the second file as a tameplate, as you suggest also, but
>consider the use of a template.  He probably does not want to
>actually update the original, but to spawn personalized copies for
>each customer/recipient record in the data file.
>
>Since the text of the template is the material that would be repeated
>each time through the loop, the text is what he should slurp.  Then
>he can go through the data-file record by record, making a
>personalized version from the template for each one.
>
You are probably right and that's what I meant. My description was probably a bit 
misleading. The way I do it is create the hash, slurp the template file in a scalar 
and produce an output string for each data set in the hash (which can be written to a 
new file, named after the respective hash key.

- Jan
-- 
These are my principles and if you don't like them... well, I have others. - Groucho 
Marx

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