Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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

In reply to Re: Processing CSV File by Athanasius
in thread Processing CSV File by Perl3r

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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:
    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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (2)
    As of 2018-02-25 04:00 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (312 votes). Check out past polls.