Help for this page

Select Code to Download


  1. or download this
       * Two algorithms: either 
         - traversing an array or 
    ...
       * Using ‘grep’ or ‘eq’;
       * Assuming that arrays look like qw /I am an array, yeah…/.
    
  2. or download this
        SMALL;
        UNSORTED (== no assumptions about distribution of elements);
        CONTAIN ONLY SHORT STRINGS
    
  3. or download this
       * Traversing an array should never be used for searching;
       * Using a hash is a pretty smart solution, except:
    ...
         - In any case, questions arise: is it smart to build it every tim
    +e one needs a lookup? What if the contents of an array change all the
    + time?.., etc.
        
       * There are other algorithms in CS.
    
  4. or download this
    $X = "x";
    @array = qw / x y z 1 2 3 /;
    return exists {map { $_ => 1 } @array}->{$X};
    
  5. or download this
     - a sub
     - that takes two arguments : an array of ints and an int;
     - assumes that the array is sorted;
     - uses binary search :-);
     - returns an index of the element or undef.