Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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


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

Title:
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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (10)
    As of 2014-09-17 14:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (81 votes), past polls