Search a list of records

From Rosetta Code
Revision as of 06:47, 10 October 2015 by rosettacode>Craigd (Added task description and zkl example)
Search a list of records is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Given a vector type (such as list or array), which may be homogeneous or heterogeneous, search for something. Demonstrate by searching for at least two types of things (which may require multiple examples).

Perl

<lang perl>if(grep $_ eq $needle, @haystack) { print 'Found'; }</lang>

PHP

<lang PHP>echo in_array('needle', ['hay', 'stack']) ? 'Found' : 'Not found';</lang>

zkl

<lang zkl>list:=List("one",2,3.4,2); list.find(2).println(); //-->1 list.find("one").println(); //-->0 list.index(2,3).println(); //-->3 same as find but exception if not found

                            // start searching at third position</lang>