in reply to searching for values in hashes

You need to do two things.
  1. Iterate over the array using foreach. This avoids counting the index of the array when you aren't using it.
  2. Use the exists function to test whether a value exists in the hash

The following illustrates this

#! /usr/bin/perl use strict; use warnings; my @array = qw (one two three four five); my %hash = (one => 'Extra information for one', two => 'Extra information for two'); foreach my $id (@array) { if (exists $hash{$id}) { print "ID: $id has extra info: $hash{$id}\n"; } else { print "ID: $id has no extra info\n"; } }

Replies are listed 'Best First'.
Re^2: searching for values in hashes
by aukjan (Friar) on Aug 05, 2005 at 11:08 UTC
    This was my first thought too, but this does not give the OP an index of the array to get the information directly from @extra (at least not that I know of). You would need an extra counter to keep track of the array index to accomplish this.