与< foo *>相比,glob('foo *')有哪些比较优势? [英] What are the comparative advantages of glob('foo*') over <foo*>?

查看:75
本文介绍了与< foo *>相比,glob('foo *')有哪些比较优势?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在查看 glob() 而不是 <*> .

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 post recommended using glob() rather than <*>.

我使用<*>是因为这是我很久以前学到的,并且从未考虑过.这不是一个很好的理由.

I use <*> because that is what I learned a long time ago and have never thought about it. Which is not a good reason.

您更希望使用哪种语法,为什么?

What syntax do you prefer for globbing, and why?

推荐答案

我个人认为<>非常重载.它的意思是从迭代器中读取",但是在确定哪种迭代器适合我的口味时,存在太多的魔术和微妙之处.例如<$foo><$foo{bar}>的含义完全不同,而神奇的裸露<>的含义却有所不同.

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.

我更喜欢使用glob并为句柄保留<>语法.这样做节省了弄清<>的内容是否是模式而不是句柄(或解析为一个的东西)的认知负担.就是说,如果您将<>表示法与"iterator"而不是"read"关联起来,则您可能更喜欢函数语法-至少在您想要跳过结果而不是生成列表的情况下.

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.

这篇关于与&lt; foo *&gt;相比,glob('foo *')有哪些比较优势?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆