http://www.perlmonks.org?node_id=998164


in reply to help with comparing two arrays of phrases

The problem is that this:

$temp_array[1] =~ s/\(\)//g; # Remove parentheses to avoid mishaps + during pattern matching

Will only remove parenthesis if the appears in together in matched pairs.

Ie. It would remove these "fred () bill () john", but not these "(fred)(bill john)".

A better way to remove all parens is to use tr///. Eg.  $temp_array[1] =~ tr/()//d;

You could also use:  $temp_array[1] =~ s/[()]//g;


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

RIP Neil Armstrong

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

    Thanks, that sure solved the "Unmatched parenthesis in regex" problem. But I'm still not getting any output. As you can see from the sample input, the two phrases have more than one word which are the same..

      You need to look closely at your code and consider carefully what you are doing. Your code in no way matches up with your description.

      1. You say you skip words less than 3 chars, but your code contains tests for <3 and <5, and the code path for >4 seems identical to that for 3 & 4.
      2. You split the first phrase into words, but not the second.

        And you then test if each word in the first phrase contains the whole of the second phrase.

      3. You have a whole bunch of else { next; } clauses.

        Do you realise that if you omitted those clauses, it would just loop to the next iteration anyway?

        So what is their purpose?

      The bottom line is, with the disparity between your written description and you code, and a bunch of redundant stuff in your code, I cannot work out what you are actually trying to achieve, so I cannot really suggest anything.

      First decide and write down what you actually want to do; then try to write code that matches that description; and then, if it doesn't do what you want, come back and ask again.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      RIP Neil Armstrong