Web lists-archives.com

Re: handling lists in perl




On 2018-12-19 00:43, deloptes wrote:
deloptes wrote:

if ( @array =~ /$hash[$key]/) {
print "key $key with value " . $hash{$key} .
" is in the array of values\n";
}

I checked and it seems the right answer is

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) {
        for (  @array ) {
                if ($_ eq $hash{$key} ) {
                        print "key $key with value " . $hash{$key} .
                                " is in the array of values\n";
                }
        }
}

except there is only one 100 in @array it gets me along.
thanks and David too.

mick

--
Key ID    4BFEBB31