Is perl's each function worth using?

后端 未结 8 1672
忘掉有多难
忘掉有多难 2021-01-17 11:37

From perldoc -f each we read:

There is a single iterator for each hash, shared by all each, keys, and values

8条回答
  •  旧巷少年郎
    2021-01-17 12:16

    It's best if used as it's name: each. It's probably the wrong thing to use if you mean "give me the first key-value pair," or "give me the first two pairs" or whatever. Just keep in mind that the idea is flexible enough that each time you call it, you get the next pair (or key in a scalar context).

提交回复
热议问题