Reputation: 25
I want to find if the value in $myVar is present in the constant MY_ARRAY. The following doesn't seem to work:
use constant {
MY_ARRAY => ['E1', 'E2']
};
.
.
my $myVar = 'E2';
if ( grep( /^$myVar$/, MY_ARRAY ) ) {
...
}
Upvotes: 0
Views: 286
Reputation: 50677
You have to dereference it with @{}
if ( grep( $_ eq $myVar, @{+MY_ARRAY} ) ) {
# ...
}
Upvotes: 2