这段代码实际上做了什么?
@array = ( 'hai','hello','bar','foo' ) ;
print grep (/hai/ , @array );
print grep ("hai",@array ) ;
print map (/hai/ , @array );
print map ("hai",@array ) ;
答案 0 :(得分:11)
答案 1 :(得分:7)
尝试一下......
print grep (/hai/ , @array );
hai
# writes all elements from @array containing 'hai' in them
print grep ("hai",@array ) ;
haihellobarfoo
# writes all elements, because "hai" evaluates to true
print map (/hai/ , @array );
1
# writes 1 for the only element from the @array, that contains 'hai'
print map ("hai",@array ) ;
haihaihaihai
# maps 'hai' to each element from @array