Chromer
Chromer

Reputation: 25

perl: grep on constant array

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

Answers (1)

mpapec
mpapec

Reputation: 50677

You have to dereference it with @{}

if ( grep( $_ eq $myVar, @{+MY_ARRAY} ) ) {
  # ...
}

Upvotes: 2

Related Questions