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
and to declare lexical variables using my.
Hope that helps,
Update 2: I created two files:
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:
this is the here to be in!
my name is fred.
the frame is '44'.
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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] |