Hello Perl3r, and welcome to the Monastery!
You are opening the output file $ofile_name each time through the outer while loop. This truncates the file each time before writing to it! Move the statement open(OFILE, ...) ... to before the first while loop, so that the file is opened only once.
Update 1: Sorry, I didn’t see that the name of the output file is changing on each pass of the outer loop. :-(
It is also good practice to begin your scripts with
use strict;
and to declare lexical variables using my.
Hope that helps,
Update 2: I created two files:
(1) “data.csv”
here,fred,42,43,44,45
there,wilma,2,5,7,9
(2) “rtr-template.txt”
this is the ##location## to be in!
my name is ##rtrname##.
the frame is '##frame-DLCI##'.
Then I invoked your original script as:
perl test_script.pl data.csv
And the result was two output files:
(a) “fred.txt“
this is the here to be in!
my name is fred.
the frame is '44'.
(b) “wilma.txt”
this is the there to be in!
my name is wilma.
the frame is '7'.
— which is exactly as expected. So, I cannot reproduce the problem you are seeing. Are you sure you are running the code as described?
Athanasius <°(((>< contra mundum
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.