|
|
| P is for Practical | |
| PerlMonks |
Re^2: Processing CSV Fileby Kenosis (Deacon) |
| on Oct 03, 2012 at 07:57 UTC ( #997000=note: print w/ replies, xml ) | Need Help?? |
|
If I may suggest considering a slightly different approach to your task... It appears that you're opening the template file each time a csv line is read, so that you can fill in the template with the entries. Consider opening the template file only once, and grabbing its contents into a scalar. Then, you can do the substitutions on a copy of that scalar, and write that copy to a file. Doing that may look something like this:
You'll notice this notation: @hash{@vars} = split /,/; It pairs the elements of @var as keys with the split entries of the csv line as values of %hash. This creates the hash that's used in the substitution line, taking the place of the six substitution lines. Also, note that the substitution is global, because your script was going through all the lines of the template for the substitutions. Hope this helps!
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||