Recent Articles
- Simple Web Crawler in Perl, Started by blitzcoder in Perl
- Twitter Controlled RAT (Mobile accessible), Started by gotroot in Perl
- Multiple Choice Questions in PERL, Started by ungalnanban in Perl
- Ceil/Floor/Round in Perl, Started by pradeep in Perl
- Access Amazon S3 Service using Perl, Started by pradeep in Perl
Similar Articles
- PERL - The String Form: Expression Evaluation, Started by shree in Perl
- ucwords functionality in Perl, Started by pradeep in Perl
- Shortcuts in Perl, Started by pradeep in Perl
Introduction
One of the strengths of PHP when it comes to arrays is considered to be the in_array function (http://php.net/in_array), this function takes two parameters; the array and the item to be searched in the array and then returns a boolean result whether the item exists in the array. Perl inherently lacks this functionality, even popular Perl modules like List::Util lack such a function/method.
As it was said by Plato once, "Necessity... the mother of invention.", I required to check whether a name existed in an array, bored by using conventional method of iterating the array every time I need to check, I wrote a simple sub-routine to get the job done.
This sub-routine take two arguments, a reference to the array to be searched, and the item that needs to be searched. Simple enough the sub-routine works like magic, even my friend have found it very useful. I thought may be someone might find it useful, here's it, take a look.
Code: Perl
Sample Usage
Code: Perl
Output :
Code:
[pradeep@go4expert ~]$ ./amlan_test.pl Hurray! Amlan you are in!! [pradeep@go4expert ~]$











Yet to provide details about himself




The solution of pradeep is very slow. This seems obvious since he is creating a big structure in memory.
The grep is fast since runs in C code inside the machine, but has to check all the elements.
The foreach stops when finds the first matching, so just half the match are needed in average.
Linear Mode

