我有两个文件。一个是从数据库中转储的表创建字符串文件,另一个是表的名称,前缀为“prompt”,后缀为“...”。如下:文件A(索引):
prompt branch...
prompt branch_param...
prompt branch_pre_param...
prompt business...
prompt business_map...
prompt business_type...
文件 B(转储):
CREATE TABLE "KS"."BRANCH"
("BRANCH_CODE" CHARACTER(3) NOT NULL DEFAULT '',
"BRANCH_NAME" CHARACTER(40) NOT NULL DEFAULT '',
"PARAM_LEVEL" INTEGER NOT NULL DEFAULT 0
)
DATA CAPTURE NONE
IN "LONG_DATA_TBS";
CREATE TABLE "KS"."BRANCH2BANK"
("BRANCH_CODE" CHARACTER(3) NOT NULL DEFAULT '',
"BANK_CODE" CHARACTER(6) NOT NULL DEFAULT '',
"ACC_COMP_RESULT" CHARACTER(1) NOT NULL DEFAULT ''
)
DATA CAPTURE NONE
IN "SMALL_TBS";
CREATE TABLE "KS"."BRANCH2BOND"
("BRANCH_CODE" CHARACTER(3) NOT NULL DEFAULT '',
"BOND_CODE" CHARACTER(8) NOT NULL DEFAULT '',
"BOND_NAME" CHARACTER(20) NOT NULL DEFAULT '',
"TOTAL_AMT" DECIMAL(19, 4) NOT NULL DEFAULT 0,
"FINANCING_CUST_NO" CHARACTER(10) NOT NULL DEFAULT '',
"SET_DATE" CHARACTER(8) NOT NULL DEFAULT '',
"SET_TIME" CHARACTER(8) NOT NULL DEFAULT '',
"SET_EMP" CHARACTER(6) NOT NULL DEFAULT '',
"SPARE1" CHARACTER(20) NOT NULL DEFAULT '',
"SPARE2" CHARACTER(20) NOT NULL DEFAULT ''
)
DATA CAPTURE NONE
IN "SMALL_TBS";
CREATE TABLE "KS"."BRANCH_PARAM"
("BRANCH_CODE" CHARACTER(3) NOT NULL DEFAULT '',
"PARAM_CODE" CHARACTER(4) NOT NULL DEFAULT '',
"SET_DATE" CHARACTER(8) NOT NULL DEFAULT '',
"SET_TIME" CHARACTER(8) NOT NULL DEFAULT ''
)
DATA CAPTURE NONE
IN "SMALL_TBS";
CREATE TABLE "KS"."BRANCH_RESERVE_CREDIT_STOCK"
("BRANCH_CODE" CHARACTER(3) NOT NULL DEFAULT '',
"SET_TIME" CHARACTER(8) NOT NULL DEFAULT ''
)
DATA CAPTURE NONE
IN "TX_DATA_TBS"
INDEX IN "TX_INDEX_TBS";
我已经编写了一个 perl 实现,但我认为它太丑陋且效率低下。有没有更好的方法来改善这一点?
我的代码:(用 Richard 和 lilydjwg 的建议重写)(最新版本)
#!/usr/bin/perl
use 5.016;
my (%hash,$cont);
open IN,'<',shift;
while(<IN>){
chomp;
$hash{$1}=1 if /prompt (\w+)\.\.\./;
}
close IN;
open IN,'<',shift;
while(<IN>){
chomp;
$cont = (defined $hash{lc $1}?say "prompt $1..." : 0) if /CREATE TABLE "KS"\."(\w+)"/;
say if $cont == 1;
}
close IN;