I'm trying to compare two lists. I have read in two files and stored them as lists. one files contains a list of DB table names while another file contains a list of SQL statements. What I want to do is compare the two. If the list of DB table names match anything in the SQL file, I want to print the table name that was matched. This is the code I have written but doesn't work.
#---------------------------------------------------- #This section will contain the searched for the DB tables in the SQL f +iles #and return all lines that contain an instance of a DB table. #This will open the file that will contain the list of tables open(TABLES, '<DBtables1.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 pars ed open(UPDATE, '<updateDan.txt') or die "The file updateDan.txt could no +t be opene d\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=<UPDATE>; @tableUsed=<USED>; #declarations $W=0; $Q=0; #This will search through the files and see if the tables exist in the + file foreach $W (@tableList) { foreach $Q (@fileList) { #if (exists($Q{$W})) if($W==$Q) { #print TABLE "$W\n"; push(@tableUsed, $W); print USED @tableUsed; }#end of if else { print USED "no tables exist in the file\n"; } } }#end of foreach loop close(UPDATE); close(TABLES); close(USED);
#----------------------------------------------- I have tried several solutions as you can see with the commented lines that were once statements. Please if you know of a way I can do this, it will tremendously help me with my project. I am new to PERL and therefore am just beginning to learn the syntax and its capabilities. Thanks

In reply to comparing 2 lists by dhudnall

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.