There is too little context in your code sample, for example you don't show how
$arrLenA and
$arrLenB are initialised. Beyond this, I strongly suspect you're not running under
strict and
warnings, that are likely to hint you that there's something wrong with your code. As an example,
$sentencesA[$z] tells us that there should be an
@sentencesA array, but
$setencesB{$i} shows two things:
- you are probably mispelling your variable name (maybe you wanted to write sentencesB?)
- you're not using an array, but hash %setencesB
Please clean up your code, and bake a self-contained example that's easy for us to cut-and-paste into a file to see what's wrong. Strive to make it as little as possible, but working. Be sure to put
use strict;
use warnings;
at the beginning. You'll probably see that when you've got the example ready without receiving any compilation error or warning, your code will probably work
;-).
On a more general ground, there are other things to note:
- you correctly start iterating from index 0, but then you should probably set your continuation condition to $z < $arrLenA instead of <=
- if both array contain the string 'hello' repeated 10 times, the result will be 10 * 10 = 100 matches, because you're comparing each element in A to each element in B. Is this what you really want?
Hope this helps!
Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf
Don't fool yourself.