Perl的设计受到C(除了awk,sed和sh-下面的手册页)的影响之外,所以一定有一些推理背后不熟悉的C风格命名的break / last.
从Perl 1.000(1987年12月18日发布)手册页的一点历史:
[Perl] combines (in the author’s opinion,anyway) some of the best features of C,sed,awk,and sh,so people familiar with those languages should have little difficulty with it. (Language historians will also note some vestiges of csh,Pascal,and even BASIC|PLUS.)
解决方法
The semantics of ‘break’ or ‘last’ are
defined by the language (in this case
Perl),not by you.Why not think of ‘last’ as “this is
the last statement to run for the
loop”.It’s always struck me as odd that the
‘continue’ statement in ‘C’ starts the
next pass of a loop. This is
definitely a strange use of the
concept of “continue”. But it is the
semantics of ‘C’,so I accept it.By trying to map particular
programming concepts into single
English words with existing meaning
there is always going to be some sort
of mismatching oddity
另外,拉里·沃尔也有点奇怪.你看过他的照片吗?
Larry Wall http://www.wired.com/images/article/full/2007/12/larry_wall_250px.jpg