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