in reply to normal array exists question

Anonymous Monk,
I wrote a tutorial on this very topic. In your case you want to loop through the hash keys and probably use List::Util's first to determine presense in the array.
for my $key ( keys %hash ) { if ( first { $_ eq $key } @array ) { # match logic } else { # no match logic } }

Cheers - L~R

Replies are listed 'Best First'.
Re^2: normal array exists question
by JanneVee (Friar) on Jul 21, 2004 at 18:27 UTC
    Question: the List::Utils first, does do a linear scan for the first element that matches?
      JanneVee,
      The tutorial covers a bit of this, but I will go into more depth here. List::Util's first is designed to generic and portable. It is prototyped to $@ where the first argument is the code reference that will be applied to the remaining items in the list. It starts at the beginning and returns as soon as the code ref evaluates to true. This does not need to be an exact match as you could use a regex in block for instance. It does have a couple of issues with regards to efficiency.
      • It does not provide ability to pass by reference so the @_ stack of aliases has to be generated. This can be costly on large lists
      • The code reference has to be dereferenced for each item in the list until a match is found.
      Now you can roll your own to be more efficient but that defeats the purpose of having portable re-useable code. Additionally, shaving a second or two off of run time is seldom worth the programmer time required to achieve it.

      Cheers - L~R

Re^2: normal array exists question
by Anonymous Monk on Jul 22, 2004 at 07:08 UTC
    that worked great
    thanks for your help