Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想查找 $myVar 中的值是否存在于常量 MY_ARRAY 中。以下似乎不起作用:
use constant { MY_ARRAY => ['E1', 'E2'] }; . . my $myVar = 'E2'; if ( grep( /^$myVar$/, MY_ARRAY ) ) { ... }
你必须取消引用它@{}
@{}
if ( grep( $_ eq $myVar, @{+MY_ARRAY} ) ) { # ... }