On Dec 6, 12:49 am, [EMAIL PROTECTED] (David Gilden) wrote:
> This is adding to many ',' in my output and do not see why!
>
> Could some one could point where I have gone wrong.

Well for one, by posting code that you're not actually running, so
people can't actually help you.

> data in: (one row of many)
> 35, 'Mike Hoffman', '', '2565 Davis Blvd. #177', '', 'Ft. Worth', '75252', 
> 'Texas', 'United States', '972267-2820', '[EMAIL PROTECTED]', 2, 'Mike 
> Hoffman', '', '2565 Davis Blvd. #177', '', 'Ft.', '75252', 'Texas', 'United 
> States', 2, 'Richard Hoffman', '', '6565 Davis Blvd. #177', '', 'Dallas', 
> '75252', 'Texas', 'United States', 2, 'Authorize.net AIM', 'Visa', 'Richard 
> Hoffman', '5446731215700551', '0807', '2007-07-03 15:12:30', '2007-07-02 
> 19:35:44', 3, NULL, 'USD', 1.000000, NULL
>
> output #not correct  # note the end of this string
> (35, 'Mike Hoffman', '', '2565 Davis Blvd. #177', '', 'Ft. worth', '75252', 
> 'Texas', 'United States', '972267-2820', '[EMAIL PROTECTED]', 2, 'Mike 
> Hoffman', '', '2565 Davis Blvd. #177', '', 'Ft. worth', '75252', 'Texas', 
> 'United States', 2, 'Mike Hoffman', '', '2565 Davis Blvd. #177', '', 'Ft. 
> worth', '75252', 'Texas', 'United States', 2, 'Authorize.net AIM', 'Visa', 
> 'Mike Hoffman', '5446731215700551', '0809', '2007-07-08 21:30:10', 
> '2007-07-05 16:01:48', 3, NULL, 'USD', 1.000000, 
> NULL,'','','','','','','','','','','','','','','','','','','','','','','','-','','','','','','',,,'',,'','','','',,'','','','','','',,,,)

> #!/usr/bin/perl -w
>
> $fileIn = "orders-raw.txt" ;
> $CleanCSV = "clean_orders_insert.txt";
>
> ####
> open (FH, $fileIn) or &errorMsg("Problem reading $fileIn $!\n");
>
> while(<FH>){
> push(@record, $_);}
>
> close FH;
>
> sub errorMsg{
> $_ = shift;
> print "Error: $_\n";
>
> }
>
> open(CSV_OUT,">$CleanCSV") or &errorMsg( "Write out,  Could not write file: 
> $CleanCSV, $!");
>
> foreach (@record){
> chomp;  
> #Split each line
> my @tmpArray  = split(/","/,$_);
> my @tmpArray  = split(/","/,$_);

Ignoring for the moment that you're doing the same exact command
twice, including declaring the variable, look what you're splitting
on.  You're splitting on a double quote followed by a comma followed
by a double quote.   Your data above is not separated by a doublequote
followed by a comma followed by a double quote.  Your fields are
separated by commas followed by spaces. Therefore, your @tmpArray
contains exactly one element - the entire string.   But then you're
going ahead and assuming there are 42 elements in the array, and
trying to assign variables to all 42 of them, and then printing out 42
different variables.

<snip>

> print CSV_OUT 
> "($customers_id,$customers_name,$customers_company,$customers_street_addres-s,$customers_suburb,$customers_city,$customers_postcode,$customers_state,$c-ustomers_country,$customers_telephone,$customers_email_address,$customers_a-ddress_format_id,$delivery_name,$delivery_company,$delivery_street_address,-$delivery_suburb,$delivery_city,$delivery_postcode,$delivery_state,$deliver-y_country,$delivery_address_format_id,$billing_name,$billing_company,$billi-ng_street_address,$billing_suburb,$billing_city,$billing_postcode,$billing_-state,$billing_country,$billing_address_format_id,$payment_method,$payment_-module_code,$shipping_module,$shipping_method,$coupon_code,$cc_type,$cc_own-er,$cc_number,$cc_expires,$cc_cvv,$last_modified,$date_purchased,$orders_st-atus,$orders_date_finished,$currency,$currency_value,$order_total,$order_ta-x,$paypal_ipn_id,$ip_address)\n";

I'm not looking at all of this mess, but where the hell did
$ip_address and $paypal_ipn_id come from?  They're not listed among
your 42 variables.   Post code that you're actually running.

Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to