#C:\PERL\bin\perl.exe -w #****PACKAGES****# use strict; use DBI; use DBD::Oracle qw(:ora_types); use XML::Parser; ##****END PACKAGES****# #****VARIABLES****# my $username = 'system'; my $password = ''; my $database = "dbi:Oracle:"; my $oradbh; my $xmlSQL; my $sqlXML; my $xmldatafile = "E:\\\\PERLFiles\\trash\\xmldata.xml"; my $datadump = "E:\\\\PERLFiles\\trash\\extract.txt"; my $idNum=1; my $driverCount=0; my $vehicleCount=0; my @policyInfo; my @driversInfo; my @vehiclesInfo; #****END VARIABLES****# #****PROGRAM****# $oradbh = DBI->connect($database,$username,$password, {RaiseError => 1, PrintError => 0}) or die ($DBI::errstr, "\n"); #Sets the Long Read Length to accomendate the XML in the RFI_XML column $oradbh -> {LongReadLen} = 30000*256; #SQL setup to extract the XML data from the 8i database $xmlSQL = qq(select rfi_xml from webrater_owner.quote where rownum between 1 and 50); $sqlXML = $oradbh->prepare($xmlSQL); $sqlXML -> execute(); my ($xml_sql_data); $sqlXML -> bind_columns(undef, \$xml_sql_data); #Write out all the XML data from RFI_XML to a text/xml file open(FILE,"> $xmldatafile") or die "Unable to open $xmldatafile : $!\n"; while($sqlXML -> fetch()) { print FILE $xml_sql_data; } close(FILE) or warn "Unable to close $xmldatafile: $!\n"; $sqlXML -> finish(); #Finish the SQL command $oradbh -> disconnect; #Disconnect from the database open(FILE, "$xmldatafile") or die "Unable to open $xmldatafile : $!\n"; open(FILE2, "> $datadump") or die "Unable to open $datadump : $!\n"; print FILE2 "IDNum|Quote#|Effective Date|Last Name|First Name|Address|City|State|Zip|Driver0 Last Name|Driver0 First Name|Sex|Marital Status|DOB|License Number|License State|Status|Driver#|Year|Make|Model|VIN|Vehicle#\n"; while() { if (/^/) { #print "new record set\n"; } elsif(m[(<.*?>)(.*?)()]x) #$1..$3 { if ($1 eq '') { $policyInfo[0] = $2; } if ($1 eq '') { $policyInfo[1] = $2; } if ($1 eq '') { $policyInfo[2] = $2; } if ($1 eq '') { $policyInfo[3] = $2; } if ($1 eq '') { $policyInfo[4] = $2; } if ($1 eq '') { $policyInfo[5] = $2; } if ($1 eq '') { $policyInfo[6] = $2; } if ($1 eq '') { $policyInfo[7] = $2; } *****PROBLEM START***** if (/^ 0) { #$driverCount++; @driversInfo = (); #clear the array for driverInfo print "array cleared\n"; } } elsif(m[(<.*?>)(.*?)()]x) { if($1 eq '') { $driversInfo[0] = $2; } if($1 eq '') { $driversInfo[1] = $2; } if($1 eq '') { if($2 eq 'male') { $driversInfo[2] = 'M'; } else { $driversInfo[2] = 'F'; } } if($1 eq '') { $driversInfo[3] = $2; } if($1 eq '') { $driversInfo[4] = $2; } if($1 eq '') { $driversInfo[5] = $2; } if($1 eq '') { $driversInfo[6] = $2 } if($1 eq '') { $driversInfo[7] = $2; } } elsif(/<\/driver>/) { $driverCount++; print "New Driver Number $driverCount\n"; } *****PROBLEM END***** if(/^)(.*?)()]x) { if($1 eq '') { $vehiclesInfo[0] = $2; } if($1 eq '') { $vehiclesInfo[1] = $2; } if($1 eq '') { $vehiclesInfo[2] = $2; } if($1 eq '') { $vehiclesInfo[3] = $2; } } elsif(/^<\/vehicle>/) { #Left blank for a reason } # print "$quote|$effectdate|$lastname|$firstname|$appAdd|$appCity|$appState|$appZip\n"; } elsif(/^<\/rfi>/) { print "\n@policyInfo\n"; print "Driver Number: $driverCount\n"; print "@driversInfo\n"; print "Vehicle Number: $vehicleCount\n"; print "@vehiclesInfo\n"; #print "$idNum|$policyInfo[0]|$policyInfo[1]|$policyInfo[2]|$policyInfo[3]|$policyInfo[4]|$policyInfo[5]|$policyInfo[6]|$policyInfo[7]|$driversInfo[0]|$driversInfo[1]|$driversInfo[2]|$driversInfo[3]|$driversInfo[4]|$driversInfo[5]|$driversInfo[6]|$driversInfo[7]|$driverCount|$vehiclesInfo[0]|$vehiclesInfo[1]|$vehiclesInfo[2]|$vehiclesInfo[3]|$vehicleCount\n"; #$idNum++; } } close(FILE); close(FILE2); #****END PROGRAM****#