有没有机会
foreach my $elements(keys %my_hash){
if($element =~ /some_expression/{
do something;
}
}
在一个声明中,如
foreach my $elements (keys %my_hash) =~ /some expression/{
do something;
}
答案 0 :(得分:7)
foreach my $elements (grep /some_expression/, keys %my_hash) {
do something;
}
答案 1 :(得分:5)
您可以使用grep
内置:
for my $element (grep /some_expression/, keys %my_hash) {
do_something();
}