不止一种方法去做一件事(There's more than one way to do it,die unless flaky_operation似乎表明了这个操作很难成功,发音“Tim Toady Bicarbonate”)。能给出更多信息。以下3种: if (not flaky_operation){ die; } 和 flaky_operation or die; 和 die unless flaky_operation; 比较这3种方式,尤其是易读, print if 1..3 or /match/ 或者更传统的: if(1..3 || /match/) { print} 或者甚至更详细: use English; if( $INPUT_LINE_NUMBER >= 1 and $INPUT_LINE_NUMBER <= 3 or $ARG =~ m/match/ ) { print $ARG; } 发展 这条俗语在Perl社区里被讨论了很多,更好的方式是一个错误时抛出异常而不是返回假的flaky_operation。但大部分Perl函数都不是这样的。因为当做一件事有很多不同方法时,这使得很容易可以写出极度杂乱的程序,但有时统一也不错”(There's more than one way to do it, but sometimes consistency is not a bad thing either,TMTOWTDI或TIMTOWTDI,但在需要的情况下也有次要的替代方法。

评论专区