in reply to help with comparing two arrays of phrases

The reason you're getting no results is because your comparison is the wrong way around :). You are checking to see if the word matches the regex with the entire 2nd phrase instead of the other way around.
I've taken the liberty of changing a few other things (sorry, couldn't resist). Amongst other things, the changes are in
use strict; use warnings; use v5.10; my @data = <>; my $match_count = 1; foreach my $line (@data) { chomp ($line); print "Processing line [$line]\n"; $line =~ s/[",\/-]/ /g; # Change all potential word endings to +a single space $line =~ s/[()]//g; # Remove parentheses to avoid mishaps d +uring pattern matching my ($id, $source, $comparison) = split "\t", $line; # Split col +umns into an array foreach my $word (split ' ', $source) { given (length $word) { when ($_ < 3) { next; } when ($_ < 5) { if ($comparison =~ /$word/i) { print "Match [$match_count] (probable): [$word]\n" +; $match_count++; } } default { if ($comparison =~ /$word/i) { print "Match [$match_count]: [$word]\n"; $match_count++; } } } } }

Replies are listed 'Best First'.
Re^2: help with comparing two arrays of phrases
by sdtej (Initiate) on Oct 18, 2012 at 07:40 UTC

    Sorry for the late reply. Could not get online for a few days!!

    @Neighbor: Thanks for cleaning the code! This does look way better than mine, and will use your code for subsequent purposes :)

    @BrowserUk: Yes, my code does look confusing being the novice I am. However, I will keep those points you mentioned in mind from now on. Thanks a lot for all your suggestions and corrections!! :)