drodinthe559 has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Text::CSV_XS; Type Method
by Anonymous Monk on Feb 18, 2010 at 17:06 UTC | |
Re: Text::CSV_XS; Type Method
by ikegami (Patriarch) on Feb 18, 2010 at 17:03 UTC | |
by drodinthe559 (Monk) on Feb 18, 2010 at 17:28 UTC | |
by ikegami (Patriarch) on Feb 18, 2010 at 18:13 UTC | |
by drodinthe559 (Monk) on Feb 18, 2010 at 22:29 UTC | |
Re: Text::CSV_XS; Type Method
by snopal (Pilgrim) on Feb 18, 2010 at 17:11 UTC | |
by drodinthe559 (Monk) on Feb 18, 2010 at 17:32 UTC |
Back to
Seekers of Perl Wisdom