What you have is a function that tells whether one or more entries in the array contain a given substring. That's not the same as searching for a number.
Consider the difference between
andmy @matches = grep { /$l_number/ } @numbers;
The former will match "11" when you're searching for a "1". That latter won't.my @matches = grep { $_ == $l_number } @numbers;
That problem aside, have you considered an alternate data structure? If you're going to be doing multiple probes for numbers, you might be better served by building a hash keyed by the number in each @number. Then, determining if a given number exists in the "array" becomes
Also, returning the strings "TRUE" or "FALSE" makes writingif ( $number{$l_number} ) { ...
problematic, because the function will always return a non-false value. Return 0 (for false) and 1 (for true), and you'll save yourself a lot of grief later.if ( checknumber(47) ) { ...
In reply to Re: Very slow array searching
by dws
in thread Very slow array searching
by Rafaqat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |