Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

“A meeting at the Liquor-Vodka Factory”, or… same ARRAY questions again?!!

by Mabooka-Mabooka (Sexton)
on Sep 02, 2005 at 20:14 UTC ( [id://488776]=perlquestion: print w/replies, xml ) Need Help??

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.
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://488776]
Approved by graff
Front-paged by ghenry
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-25 19:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found