Okay, I have had a closer look at this one.

First of all, that edit sub seems to be a bit of a red herring, as it appears to have nothing to do with the rest of the code.

I have modified the rest of the code so it will run standalone, and enabled strict and warnings.

I also created a dummy cvsin file to read from.

So, we have....

darren@barney:~/perlmonks$ cat csvin replace_me merry xmas hello world perlmonks replace_me just another Perl hacker,

And the modified code...

#!/usr/bin/perl -w use strict; my $rim1_thecode = "csvout"; my $CSV_file = "csvin"; my $thecode = "replace_me"; if ($rim1_thecode ne "") { ##generate RIM1 csv file## open (CSVIN, "<$CSV_file") or die "Can't open $CSV_file: $!\n"; my $outcsv_file = $rim1_thecode."\.csv"; open (CSVOUT, ">$outcsv_file") or die "Can't open $outcsv_file: $! +\n"; my @lines = <CSVIN>; for my $line (@lines) { ##substitute $thecode with RIM1 transaction code## $line =~ s/$thecode/$rim1_thecode/; print CSVOUT $line; } close CSVIN; close CSVOUT; }

Which when run creates the file csvout.csv, which looks like so..

darren@barney:~/perlmonks$ cat csvout.csv csvout merry xmas hello world perlmonks csvout just another Perl hacker,

As you can see, all the instances of "replace_me" have been replaced with "csvout", which is exactly as expected. However, I'm quite certain this isn't what you are trying to achieve. I think what you need to do now is explain as clearly as possible precisely what it is you are trying to do, and then we may be able to help you further.

Cheers,
Darren :)


In reply to Re: generate new files by McDarren
in thread generate new files by tkn

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!
  • 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, details, 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, summary, 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.