sasuser2006
Technical User
I'm trying to create a perl script that creates a sql script to load a table to a database based on a CSV file that's passed to perl and I'm having a problem. Currently the piece of the code says:
The problem is in the $sql_line definition it adds a comma which I want except for the final time it goes through. Basically I have:
IP_State varchar2(2),
IP_ZIP varchar2(5),
IP_ZIP4 varchar2(4),
And I want:
IP_State varchar2(2),
IP_ZIP varchar2(5),
IP_ZIP4 varchar2(4)
No comma after IP_ZIP4 varchar2(4)
Can somebody please help me fix this? Thanks ahead of time for any help.
Code:
...
open (CSV_FILE, "$csv_file") or die "Can't open $csv_file: $!";
open (SQL_FILE, ">$sql_file") or die "Couldn't open $sql_file: $!";
while (<CSV_FILE>)
{
chomp;
$line = $_;
{
my $field = (split (/,/, $line))[0,0];
my $type = (split (/,/, $line))[0,4];
my $field_length = (split (/,/, $line))[0,3];
my $sql_line= $field . " " . $type . "(" . "$field_length" . "),";
print SQL_FILE "\t\t\t$sql_line\n";
}
}
...
The problem is in the $sql_line definition it adds a comma which I want except for the final time it goes through. Basically I have:
IP_State varchar2(2),
IP_ZIP varchar2(5),
IP_ZIP4 varchar2(4),
And I want:
IP_State varchar2(2),
IP_ZIP varchar2(5),
IP_ZIP4 varchar2(4)
No comma after IP_ZIP4 varchar2(4)
Can somebody please help me fix this? Thanks ahead of time for any help.