Home > Archive > PERL Beginners > December 2007 > DB Conversion script issues
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
DB Conversion script issues
|
|
| David Gilden 2007-12-09, 8:00 am |
| Greetings,
Could some please tell me why this writing the data like think it should.
Input data:
4,'Daniel Niederer','','Wberweg 3A','','Hersiwil','
Sample of the output: (first 4 'columns' )
4,'Daniel Niederer','','Wberweg 3A','','Hersiwil','4558',
I would think it should print to disk the following ::
0 : 4,'name: Daniel Niederer','','Wberweg 3A','','Hersiwil','4558',
=20
$customers_id=3D $count++ . " : ". $tmpArray[0] || "''";
$customers_name=3D "name : " . $tmpArray[1] || ;
But it does not!! <!!!@##!@#>
If anyone can set me straight on how to make my script behave
that would be most helpful.
Thx!
Dave Gilden
(kora musician / audiophile / webmaster @ www.coraconnection.com / Ft. Wor=
th, TX, USA) =20
---
#!/usr/bin/perl -w
$fileIn =3D "orders-raw.txt" ;
$CleanCSV =3D "clean_orders_insert.txt";
####
open (FH, $fileIn) or &errorMsg("Problem reading $fileIn $!\n");
while(<FH> ){
push(@record, $_);=20
}=20
close FH;
sub errorMsg{
$_ =3D shift;
print "Error: $_\n";
}
$count =3D0;
open(CSV_OUT,">$CleanCSV") or &errorMsg( "Write out, Could not write file:=
$CleanCSV, $!");
=20
foreach (@record){
chomp; =20
#Split each line
my @tmpArray =3D split(/","/,$_);=20
$customers_id=3D $count++ . " : ". $tmpArray[0] || "''";
$customers_name=3D "name : " . $tmpArray[1] || "''";
$customers_company=3D $count++ . " : ". $tmpArray[2] || "''";
$customers_street_address=3D $count++ . " : ". $tmpArray[3] || "''";
$customers_suburb=3D $count++ . " : ". $tmpArray[4] || "''";
$customers_city=3D $count++ . " : ". $tmpArray[5] || "''";
$customers_postcode=3D $count++ . " : ". $tmpArray[6] || "''";
$customers_state=3D $count++ . " : ". $tmpArray[7] || "''";
$customers_country=3D $count++ . " : ". $tmpArray[8] || "''";
$customers_telephone=3D $count++ . " : ". $tmpArray[9] || "''";
$customers_email_address=3D $count++ . " : ". $tmpArray[10] || "''";
$customers_address_format_id=3D $count++ . " : ". $tmpArray[11] || "''";
$delivery_name=3D $count++ . " : ". $tmpArray[12] || "''";
$delivery_company=3D $count++ . " : ". $tmpArray[13] || "''";
$delivery_street_address=3D $count++ . " : ". $tmpArray[14] || "''";
$delivery_suburb=3D $count++ . " : ". $tmpArray[15] || "''";
$delivery_city=3D $count++ . " : ". $tmpArray[16] || "''";
$delivery_postcode=3D $count++ . " : ". $tmpArray[17] || "''";
$delivery_state=3D $count++ . " : ". $tmpArray[18] || "''";
$delivery_country=3D $count++ . " : ". $tmpArray[19] || "''";
$delivery_address_format_id=3D $count++ . " : ". $tmpArray[20] || "''";
$billing_name=3D $count++ . " : ". $tmpArray[21] || "''";
$billing_company=3D $count++ . " : ". $tmpArray[22] || "''";
$billing_street_address=3D $count++ . " : ". $tmpArray[23] || "''";
$billing_suburb=3D $count++ . " : ". $tmpArray[24] || "''";
$billing_city=3D $count++ . " : ". $tmpArray[25] || "''";
$billing_postcode=3D $count++ . " : ". $tmpArray[26] || "''";
$billing_state=3D $count++ . " : ". $tmpArray[27] || "''";
$billing_country=3D $count++ . " : ". $tmpArray[28] || "''";
$billing_address_format_id=3D $count++ . " : ". $tmpArray[29] || "''";
$payment_method=3D $count++ . " : ". $tmpArray[30] || "''";
$cc_type=3D $count++ . " : ". $tmpArray[32] || "''";
$cc_owner=3D $count++ . " : ". $tmpArray[33] || "''";
$cc_number=3D $count++ . " : ". $tmpArray[35] || "''";
$cc_expires=3D $count++ . " : ". $tmpArray[34] || "''";
$orders_status=3D $count++ . " : ". $tmpArray[37] || "''";
$orders_date_finished=3D $count++ . " : ". $tmpArray[38] || "''";
$currency=3D $count++ . " : ". $tmpArray[39] || "''";
$currency_value=3D $count++ . " : ". $tmpArray[40] || "''";
$shipping_module=3D $count++ . " : ". $tmpArray[41] || "''";
$last_modified=3D $count++ . " : ". $tmpArray[35] || "''";
$date_purchased=3D $count++ . " : ". $tmpArray[36] || "''";
$orders_status =3D $count++ . " : ". "'*'";
$orders_date_finished =3D $count++ . " : ". "''";
$currency =3D $count++ . " : ". "''";
$currency_value =3D $count++ . " : ". "''";
$order_total =3D $count++ . " : ". "''";
$order_tax =3D $count++ . " : ". "''";
$paypal_ipn_id =3D $count++ . " : ". "''";
$ip_address =3D $count++ . " : "."'*'";
# Write TMP file=20
print CSV_OUT " ($customers_id,$customers_name,$customer
s_company,$customers=
_street_address,$customers_suburb,$custo
mers_city,$customers_postcode,$cust=
omers_state,$customers_country,$customer
s_telephone,$customers_email_addres=
s,$customers_address_format_id,$delivery
_name,$delivery_company,$delivery_s=
treet_address,$delivery_suburb,$delivery
_city,$delivery_postcode,$delivery_=
state,$delivery_country,$delivery_addres
s_format_id,$billing_name,$billing_=
company,$billing_street_address,$billing
_suburb,$billing_city,$billing_post=
code,$billing_state,$billing_country,$bi
lling_address_format_id,$payment_me=
thod,$payment_module_code,$shipping_meth
od,$shipping_module_code,$coupon_co=
de,$cc_type,$cc_owner,$cc_number,$cc_exp
ires,$cc_cvv,$last_modified,$date_p=
urchased,$orders_status,$orders_date_fin
ished,$currency,$currency_value,$or=
der_total,$order_tax,$paypal_ipn_id,$ip_
address)\n";
}
close(CSV_OUT);
| |
| Tom Phoenix 2007-12-09, 7:01 pm |
| On 12/8/07, David Gilden <dowda@coraconnection.com> wrote:
> Could some please tell me why this writing the data like think it should.
I'm not sure what you're asking. Is there a verb in your sentence? Is
it missing some other key words? I think your perl binary is doing
what you asked of it.
> Input data:
> 4,'Daniel Niederer','','Wberweg 3A','','Hersiwil','
>
> Sample of the output: (first 4 'columns' )
> 4,'Daniel Niederer','','Wberweg 3A','','Hersiwil','4558',
That doesn't look like four columns to me. How do you count it?
> I would think it should print to disk the following ::
>
> 0 : 4,'name: Daniel Niederer','','Wberweg 3A','','Hersiwil','4558',
>
> $customers_id= $count++ . " : ". $tmpArray[0] || "''";
> $customers_name= "name : " . $tmpArray[1] || ;
That code doesn't print anything. Do you mean that you want a program
to output Perl code?
> #!/usr/bin/perl -w
>
> $fileIn = "orders-raw.txt" ;
> $CleanCSV = "clean_orders_insert.txt";
Have you heard that you should start nearly every program with "use
strict" and "use warnings"? It's a good first step, before asking for
help.
> $customers_id= $count++ . " : ". $tmpArray[0] || "''";
> $customers_name= "name : " . $tmpArray[1] || "''";
> $customers_company= $count++ . " : ". $tmpArray[2] || "''";
> $customers_street_address= $count++ . " : ". $tmpArray[3] || "''";
> $customers_suburb= $count++ . " : ". $tmpArray[4] || "''";
What is $count counting? Is it supposed to be synchronized with the
indices of @tmpArray? Do you realize that the concatenation operator
(the dot ".") is higher in precedence than the logical-or (the
vertical bars "||")?
Good luck with it!
--Tom Phoenix
Stonehenge Perl Training
|
|
|
|
|