Guru's, I'm having difficulty forcing the integers for all my fields that I'm out putting. I defined the type but I still have fields out putting as character fields.
#!/usr/bin/perl -w
use strict;
use warnings;
use Text::CSV_XS;
my ($reporttype,$sorter2,$price,$account,$amount,$check_no,$date_time,
+$prod_no,$rundate);
$reporttype = 0;
$sorter2 = 0;
$account = 0;
$amount = 0;
$check_no = 0;
my $procdate = sprintf "%02d%02d%02d%02d%02d%02d", (localtime)[4]+1, (
+localtime)[3], substr((localtime)[5]+1900,2,2),(localtime)[2], (local
+time)[1], (localtime)[0];
open SOURCE, "< C:/B01.PRN" or die "can't open file $!";
open CSVFILE, ">> C:/test_" . $procdate . ".csv";
my $csv = Text::CSV_XS->new({eol => "\n"});
$csv->types ([Text::CSV_XS::IV (),
Text::CSV_XS::IV (),
Text::CSV_XS::IV (),
Text::CSV_XS::IV ()]);
while(my $source = <SOURCE>) {
if (substr($source,7,4) =~ /\d\d\d\d/ && $reporttype == 1 && $sort
+er2 == 1){
$prod_no = substr($source,88,8);
$account = int(substr($source,22,10));
$price = substr($source,7,9);
$check_no = substr($source,48,16);
$amount = substr($source,32,16);
#$amount =~ s/,//;
#$amount = $amount;
$csv->combine($prod_no, $account, $price, $check_no,$amount);
print $csv->string;
printf CSVFILE $csv->string;
};
};
close SOURCE;
-
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.