What are the comparative advantages of glob('foo*') over ?

后端 未结 3 1390
陌清茗
陌清茗 2021-02-19 05:10

I was just looking at Can someone tell me how to create an array of directory contents?. Unsurprisingly, file globs were offered as an answer. What surprised me was that the p

3条回答
  •  心在旅途
    2021-02-19 06:05

    Personally, I think that <> is badly overloaded. It sort of means "read from an iterator" but there's a little too much magic and subtlety in determining which iterator of what kind for my taste. e.g. <$foo> and <$foo{bar}> mean very different things, and the magical bare <> means something different yet.

    I prefer to use glob and reserve the <> syntax for handles. Doing that saves the cognitive burden of figuring out whether the contents of the <> is a pattern rather than a handle (or something that resolves to one). That said, if you mentally associate the <> notation with "iterator" instead of "read" you might prefer that to the functional syntax -- at least for those cases where you want to step over the results rather than generate a list.

提交回复
热议问题