in reply to comparing 2 lists

I think you might want to try something like this:
chomp @tableList; chomp @fileList; for $W (@tableList) { for $Q (@fileList) { if($Q =~ /$W/i) { print USED "$W\n"; } } }

This will use a simple regular expression to see if the table name $W matches anything in the query string $Q. The /i makes it case insensitive (so "two" will match "Two" or "TWO" for example.) The chomps are needed to strip off the newline character "\n" at the end of each line, else the match will fail unless the table name appears at the end of the query.

The matches will be printed to the output file, all others will be ignored.

I hope this helps - good luck!

Replies are listed 'Best First'.
Re^2: comparing 2 lists
by ikegami (Patriarch) on Jun 19, 2007 at 15:32 UTC

    You've put the table loop on the outside, which is good. If it was on the inside, you'd be compiling a lot of regexps for nothing. But it can be taken a step further.

    my $tableList = map qr/$_/i, join '|', map quotemeta, @tableList; for my $Q (@fileList) { push @tableUsed, $Q =~ /$tableList/g; }

    The OP might want to remove duplicates from @tableUsed.

    my $tableList = map qr/$_/i, join '|', map quotemeta, @tableList; my %tableUsed; for my $Q (@fileList) { for my $W ($Q =~ /$tableList/g) { ++$tableUsed{$W}; } } my @tableUsed = sort keys %tableUsed;