Skip to content

Instantly share code, notes, and snippets.

@secwang
Last active February 4, 2017 07:23
Show Gist options
  • Save secwang/f57dfe53cb4734e5abe58d42ae07e34b to your computer and use it in GitHub Desktop.
Save secwang/f57dfe53cb4734e5abe58d42ae07e34b to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8::all;
sub trim
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
if(length($string)<1){
return " ";
}else{
return $string;
}
}
my $file = "a.txt";
open my $in, "<:encoding(utf8)", $file or die "$file: $!";
my @lines = <$in>;
close $in;
chomp @lines;
for my $line (@lines) {
my @a = split ',', $line;
my $b = shift @a;
$b = trim $b;
my $c = shift @a;
$c = trim $c;
my $out = <<_EOC_;
insert into item (item_desc,item_sku) values ("$b" , "$c");\n
_EOC_
print $out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment