Skip to content

Instantly share code, notes, and snippets.

@tehsis
Created June 1, 2011 16:59
Show Gist options
  • Save tehsis/1002757 to your computer and use it in GitHub Desktop.
Save tehsis/1002757 to your computer and use it in GitHub Desktop.
SQL Import
#!/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