in reply to Processing CSV File
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Processing CSV File
by Perl3r (Novice) on Oct 03, 2012 at 06:40 UTC | |
by Kenosis (Priest) on Oct 03, 2012 at 07:57 UTC | |
by Perl3r (Novice) on Oct 04, 2012 at 00:21 UTC | |
by Kenosis (Priest) on Oct 04, 2012 at 18:09 UTC | |
by Anonymous Monk on Oct 05, 2012 at 00:44 UTC | |
|