Created
June 1, 2011 16:59
-
-
Save tehsis/1002757 to your computer and use it in GitHub Desktop.
SQL Import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
my $table = shift; | |
open(my $fh, '<',shift) or die $!; | |
my $exportfile = shift; | |
open (FILE,">",$exportfile); | |
my $fields; | |
my $firstLine = <$fh>; | |
my @reg = split(/,/,$firstLine ); | |
$fields = join(",",@reg); | |
print $fields; | |
while(<$fh>) { | |
my @reg = split(/,/,$_ ); | |
my $export = "insert into $table($fields) values(\'".(join("\',\'",@reg))."\');"; | |
print FILE $export . "\n"; | |
} | |
close(FILE); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment