I would agree that the dump may do many interesting things when it goes to CSV, including escaping certain chars. I suggest the following code (which I use a variation of to convert Semi-Colon SV files to CSV files):
use IO::File;
use Text::CSV_XS;
for (@ARGV) {
my $out_fname = $_.'.dshield';
my $inf = new IO::File ( $_,'<' ) or die "Cannot read $_";
my $outf = new IO::File ( $out_fname ,'>' ) or die "Cannot write $o
+ut_fname";
my $csv_in = new Text::CSV_XS; # defaults work for most CSV's
my $csv_out = new Text::CSV_XS({sep_char=>"\t"}); # use tabs
until ($inf->eof) {
my $line = $csv_in->getline($inf);
$csv_out->print($outf, $line);
}
} ## IO::File objects close automatically when they go out of scope
This gets used as: c2t.pl file1.out {file2.out} {...} , and writes the results to file1.out.dshield, etc. By using the Text::CSV_XS module, you will be certain of processing CSV and Tab-SV files correctly. Though it's more code, it performs quite well and it will likely save you grief in the future.
Larry Wall is Yoda: there is no try{}
The Code that can be seen is not the true Code
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|