Expand|Select|Wrap|Line Numbers
- compare_strings($string1,$string2);
- sub compare_strings
- {
- my ($searchString,$dataString) = @_;
- my (@searchString) = $searchString;
- my (@dataString) = $dataString;
- for ($i = 0;$i < @dataString - @searchString;$i++)
- {
- MISMATCH: for ($j = 0;$j < @searchString;$j++)
- {
- if($searchString[$j] ne $dataString[$i+$j])
- {
- last MISMATCH;
- }
- if ($j+1 == @searchString)
- {
- return 1;
- }
- }
- }
- return 0;
- }
It seems straightfoward to me but never returns 1, even when I know it should. I feel the algorithm is correct and the problem is instead a syntax error. Perhaps in the way the strings are passed to the subroutine.
Please, help....I'm running out of hair to pull out!
Perhaps we can see what data is being used as well? Could you please post that?
Regards,
Jeff