I have a file that contains a list of all the table names that I found when searching through SQL files. I have a file that contains ALL the tables ALONG WITH the database that they belong to as well. What I want to do is compare the file that contains JUST the tables I found in the SQL files to the file that contains the tables ALONG WITH the database. If there is a match, I want to pull the ENTIRE line (database, table) so that I can then upload the file into an excel spreadsheet. The code that I have used to pull the tables from the SQL files is as follows:
#This will open the file that will contain the list of tables
open(TABLES, '<DBtest.txt') or die "The file DBnames.txt could not be
+opened\n";
#This will open the file that will contain the list of SQL statements
+to be parsed
open(DOUT, '<databaseJoinDan.txt') or die "The file databaseJoinDan.tx
+t could no
t be opened\n";
#This will open the file that will be written to containing the list o
+f tables
#in the SQL files
open(USED, '>>tableUsed.txt') or die "The file tablesUsed.txt could no
+t be writt
en to\n";
#This will convert the files into lists to be searched
@tableList=<TABLES>;
@fileList=<DOUT>;
@tableUsed=<USED>;
#declarations
$Y=0;
$T=0;
#This will search through the files and see if the tables exist in the
+ file
chomp @tableList;
chomp @fileList;
for $Y (@tableList){
for $T (@fileList){
if($T =~ /$Y/i){
print USED "$Y\n";
}
}
}#end of the for loop
close(DOUT);
close(TABLES);
close(USED);
-Therefore, after executing this code I have a list of tables but what I REALLY WANT is a the DB along with the table name. The file that contains an ENTIRE listing of all DB names along with their tables is DatabaseTables.txt. I just want to be able to search through that file using the tables that I found in the first search to pull the ENTIRE listing (DB & TABLENAME). Please help if you can.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.