G'day stmadalli,
Welcome to the monastery.
if(exists {Keys of %line contains any values of $new{a} }) #need this
+condition
I suspect what you want is something like this:
if (grep { exists $line{$_} } @{$new{a}}) {
There are a number of syntactical problems with the code you posted.
Compare it with this example:
#!/usr/bin/env perl -l
use strict;
use warnings;
my @array = qw{a b c};
my %list = (
a => [qw{100 nuts}],
b => [qw{200 bolts}],
c => [qw{300 screws}],
);
my $msg = getMsg(\@array, \%list);
sub getMsg {
my ($aref, $href) = @_;
my %line = (
100 => [qw{abc xyz}],
nuts => [qw{def lmn}],
);
for my $key (@$aref) {
print 'Key: ', $key;
if (grep { exists $line{$_} } @{$href->{$key}}) {
print 'TRUE';
}
else {
print 'FALSE';
}
}
}
[Note how I've used qw{...} to eliminate much of the original punctuation so that the data is not lost amongst a forest of quotation marks (see perlop: Quote and Quote-like Operators). Also note the fat comma, =>, quotes its left operand so that's several more quotes that aren't needed (see perlop: Comma Operator).]
Output:
Key: a
TRUE
Key: b
FALSE
Key: c
FALSE
I don't think these are what you meant, but be aware of the built-in functions keys and values.
Also look at the first function provided by the built-in module List::Util. This can save you checking all elements of an array (with grep) when you only want to know if any element meets your condition (i.e. it stops checking as soon as the first TRUE condition is found).
|