perl子程序用不用将传递来的变量声明进@_?

骆驼书里说“perl会自动将参数列表转化为@_”,而beginning perl for bioinformatics说beware the common mistake of forgetting the @_ array when naming your arguments in a subroutine

一只名叫tom的猫
浏览 635回答 2
2回答

忽然笑

这里的意思是, 虽然你的 arguments ( 参数 )会自动装在 @_ 里, 但你还是要小心存取.sub analyst {my ( $dna, $protien, $gene ) ;...}这样并不会将 @_ 里的值赋予$dna, $protien, $gene.你得写成 :my ( $dna, $protien, $gene ) = @_;同理,sub analyst {my ( $dna, $protien, $gene ) ;( $dna ) = @_;}如果只有这样, 那麼只有第一个参数 (即 $_[0] )才会赋但给 $dna ,其他 $_[1], $_[2] 都会被忽略
打开App,查看更多内容
随时随地看视频慕课网APP