Is “map” a loop?

后端 未结 15 1825
自闭症患者
自闭症患者 2020-12-14 14:29

While answering this question, I came to realize that I was not sure whether Perl\'s map can be considered a loop or not?

On one hand, it quacks/walks l

15条回答
  •  囚心锁ツ
    2020-12-14 15:19

    No, it is not a loop, from my perspective.

    Characteristic of (perl) loops is that they can be broken out of (last) or resumed (next, redo). map cannot:

    map { last } qw(stack overflow);  # ERROR!  Can't "last" outside a loop block
    

    The error message suggests that perl itself doesn't consider the evaluated block a loop block.

提交回复
热议问题