Re: handling lists in perl
Hi,
it is not exactly clear if you want to test the key or the value of the
pairs, but I assume you are after the values.
mick crane wrote:
> I have an list of pairs
> (1=>8,2=>20,6=>100,15=>100....)
this would be a hash array (means key/value pairs)
> and an array of unique numbers
> (1 21 100 8 15 22 6 12 56.... )
This is a standard/classic array
> I want to see what pairs can be satisfied from the array of numbers,
> send that list to a file and also to another file the left over numbers.
so iterate over the hash and check for matches in the array
my %hash = ( 1=>8,2=>20,6=>100,15=>100 );
my @array = [1, 21, 100, 8, 15, 22, 6, 12, 56];
foreach my $key (keys %hash) {
if ( @array =~ /$hash[$key]/) {
print "key $key with value " . $hash{$key} .
" is in the array of values\n";
}
}
result
key 6 with value 100 is in the array of values
key 2 with value 20 is in the array of values
key 15 with value 100 is in the array of values
key 1 with value 8 is in the array of values
regards
Reply to: