<?xml version="1.0" encoding="windows-1252"?>
<node id="996984" title="Re: Processing CSV File" created="2012-10-03 02:11:11" updated="2012-10-03 02:11:11">
<type id="11">
note</type>
<author id="968231">
Athanasius</author>
<data>
<field name="doctext">
&lt;p&gt;Hello [Perl3r], and welcome to the Monastery!&lt;/p&gt;

&lt;p&gt;&lt;strike&gt;You are opening the output file &lt;tt&gt;$ofile_name&lt;/tt&gt; each time through the outer &lt;tt&gt;while&lt;/tt&gt; loop. This truncates the file each time before writing to it! Move the statement &lt;tt&gt;open(OFILE, ...) ...&lt;/tt&gt; to before the first &lt;tt&gt;while&lt;/tt&gt; loop, so that the file is opened only once.&lt;/strike&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Update 1:&lt;/b&gt; Sorry, I didn&amp;rsquo;t see that the name of the output file is changing on each pass of the outer loop.&amp;nbsp;&amp;nbsp;&lt;tt&gt;:-(&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;It is also good practice to begin your scripts with&lt;/p&gt;

&lt;code&gt;
use strict;
&lt;/code&gt;

&lt;p&gt;and to declare lexical variables using &lt;tt&gt;my&lt;/tt&gt;.&lt;/p&gt;

&lt;p&gt;Hope that helps,&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Update 2:&lt;/b&gt; I created two files:&lt;/p&gt;

&lt;p&gt;(1) &amp;ldquo;data.csv&amp;rdquo;&lt;/p&gt;

&lt;code&gt;
here,fred,42,43,44,45
there,wilma,2,5,7,9
&lt;/code&gt;

&lt;p&gt;(2) &amp;ldquo;rtr-template.txt&amp;rdquo;&lt;/p&gt;

&lt;code&gt;
this is the ##location## to be in!
my name is ##rtrname##.
the frame is '##frame-DLCI##'.
&lt;/code&gt;

&lt;p&gt;Then I invoked your original script as:&lt;/p&gt;

&lt;code&gt;
perl test_script.pl data.csv
&lt;/code&gt;

&lt;p&gt;And the result was two output files:&lt;/p&gt;

&lt;p&gt;(a) &amp;ldquo;fred.txt&amp;ldquo;&lt;/p&gt;

&lt;code&gt;
this is the here to be in!
my name is fred.
the frame is '44'.
&lt;/code&gt;

&lt;p&gt;(b) &amp;ldquo;wilma.txt&amp;rdquo;&lt;/p&gt;

&lt;code&gt;
this is the there to be in!
my name is wilma.
the frame is '7'.
&lt;/code&gt;

&lt;p&gt;&amp;mdash; which is exactly as expected. So, I cannot reproduce the problem you are seeing. Are you sure you are running the code as described?&lt;/p&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-968231"&gt;
&lt;p&gt;Athanasius&amp;emsp;&lt;font color=#008000&gt;&amp;lt;&amp;deg;(((&amp;gt;&amp;lt;&lt;/font&gt;&amp;emsp;&lt;i&gt;contra mundum&lt;/i&gt;&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
996981</field>
<field name="parent_node">
996981</field>
</data>
</node>
