in reply to Re: check if an element exists in array
in thread check if an element exists in array

I wanted to use a hash, but how will I build it? I do not have unique names...
  • Comment on Re^2: check if an element exists in array

Replies are listed 'Best First'.
Re^3: check if an element exists in array
by FunkyMonk (Bishop) on Apr 19, 2008 at 09:42 UTC
    Using @names as before...
    my %names_h = map { $_->[0] => 1 } @names; # map { @$_ } @names; # similar, but more scary my $name = 'Jim'; print "Jim's in the hash\n" if $names_h{$name};


    Unless I state otherwise, my code all runs with strict and warnings
      Thank you all, I seem to be close...
      But if I go with grep as you suggest, I DO find the names, but how do I print the numbers as well? I tried with $_->1 but didn't work...
        Assuming you mean $_->[1] (wrapping code in <code>...</code> tags preserves things like []).

        It works for me! Perhaps you should show exactly what you tried and how exactly it "didn't work".


        Unless I state otherwise, my code all runs with strict and warnings