TXT TO SQL 変換8

戻る

# DWGを抽出,中間ファイルを作成 # get_dwg1.pl 2007.10.27 use strict; use Spreadsheet::Read; my (%t,$n,@fld,$ref); # Read setting data while(<DATA>){ chomp; @fld = split(/==>/); if ( /^SQL/ ) { $t{E_DIR} = $fld[1]; $t{T_DIR} = $fld[2]; } elsif ( /^RANGE/ ) { $t{START} = $fld[1]; $t{END} = $fld[2]; } } close(DATA); $t{inputf} = $t{E_DIR} . '-files_all.txt'; # ファイル名ファイルを読む open(IN,"../$t{T_DIR}/$t{inputf}") or die "Can't open the file $t{inputf}\n"; $t{NO}=0; while(<IN>){ if ( /^FILE/ ) { chomp; @fld = split(/==>/); $t{NO}++; if ( $t{NO} >= $t{START} ) { push(@{ $t{files} },$fld[1]); } last if $t{NO} >= $t{END}; } } close(IN); open(OUT,">../$t{T_DIR}/dwg1.txt"); print OUT "Filename=dwg1.txt.\n"; # ひとつずつ処理 for $n ( 0 .. $#{ $t{files} } ) { $t{file1} = $t{files}[$n]; $ref = ReadData("../$t{E_DIR}/$t{file1}") or die "Can't open the file $t{E_DIR}/$t{file1}\n"; # B列のすべてのデータを読む print "NO=$n,file=$t{file1}\n"; $t{engine} = 0; for $n ( 1 .. $#{ $ref->[1]{cell}[2] } ) { $t{XY1} = 'B' . $n; $t{one1} = $ref->[1]{$t{XY1}}; if ( $t{one1} =~ /DWG/ or $t{one1} =~ /D\/N/ or $t{one1} =~ /DRAWING/ ) { print OUT "DWG==>$t{one1}\n"; last; } } # ファイルをクローズ undef $ref; } print "The output file is /$t{T_DIR}/dwg1.txt\n"; __DATA__ C E_DIR T_DIR SQL==>共同work==>txt C START END #RANGE==>1==>100 #RANGE==>101==>1000 RANGE==>1001==>3792 __END__; -------------------------------------------------------------------- # DWGデータのOrdering # get_dwg2.pl 2007.10.28 use strict; my (%t,$n,@fld,$ref); # Reading input data open(IN,"../txt/dwg.txt") or die "Can't open the file dwg.txt.\n"; while(<IN>){ if ( $. == 1 ) { $t{filename} = $_; } if (/^DWG/) { chop; @fld = split(/==>/); $t{list}{$fld[1]}++; } } close(IN); @{ $t{key} } = sort keys %{ $t{list} }; open(OUT,">../txt/dwgs.txt"); print OUT "Filename=dwg.txt.\n"; for $n ( 0 .. $#{ $t{key} } ) { print OUT 'DWG==>'; print OUT $t{key}[$n]; print OUT "\n"; } close(OUT); print "The output file is dwgs.txt.\n"; __END__; -------------------------------------------------------------------- # SQLファイルを生成 # get_dwg3.pl 2007.10.28 use strict; my (%t,$n,@fld,@list); # Reading input data open(IN,"../txt/dwgs.txt") or die "Can't open the file dwgs.txt.\n"; while(<IN>){ if (/^DWG/) { chop; @fld = split(/==>/); push(@list,$fld[1]); } } close(IN); open(OUT,">../sql/main_dwg1.sql"); print OUT 'DROP TABLE IF EXISTS main_dwg1;',"\n"; print OUT 'CREATE TABLE main_dwg1',"\n"; print OUT '(',"\n"; print OUT ' id INT AUTO_INCREMENT,',"\n"; print OUT ' name CHAR(50),',"\n"; print OUT ' memo CHAR(200),',"\n"; print OUT ' PRIMARY KEY (id)',"\n"; print OUT ');',"\n\n"; for $n ( 0 .. $#list ) { print OUT 'INSERT INTO main_dwg1 (name,memo) VALUES("'; print OUT $list[$n],'","X");'; print OUT "\n"; } print "The output file is main_dwg1.sql.\n";
戻る