Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a better implementation to extract a multiline text structure from one file based on the index from the other file?
    primarykey
    data
    text
    <p>I have two files. One is a file of table creation strings dumped from database, the other is the name of tables, with a "prompt" as a prefix and a "..." as suffix. Just as below: file A (index):</p> <pre><code>prompt branch... prompt branch_param... prompt branch_pre_param... prompt business... prompt business_map... prompt business_type... </code></pre> <p>file B (dump):</p> <pre><code>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"; </code></pre> <p>I have written a perl implementation, but I think it is much too ugly and inefficient. Is there a better way to improve this?</p> <p>my code: (rewritten with Richard and lilydjwg's advice) (last version)</p> <pre><code>#!/usr/bin/perl use 5.016; my (%hash,$cont); open IN,'&lt;',shift; while(&lt;IN&gt;){ chomp; $hash{$1}=1 if /prompt (\w+)\.\.\./; } close IN; open IN,'&lt;',shift; while(&lt;IN&gt;){ chomp; $cont = (defined $hash{lc $1}?say "prompt $1..." : 0) if /CREATE TABLE "KS"\."(\w+)"/; say if $cont == 1; } close IN; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload