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.
我有一个数组说@array。我想知道数组的哪些值构成哈希的键,比如 %hash。除了使用 for 循环之外,还有其他简单的方法吗?
例如,
@array = qw (a b c); %hash = ( a => 1, b=> 2 );
在这种情况下,它应该只输出“a”和“b”。
这应该这样做:
my @array = qw(a b c) ; my %hash = ( a => 1 , b => 2 ) ; my @result = grep { exists $hash{$_} } @array ;