perl笛卡尔积
http://hi.baidu.com/dayouluo/blog/item/09ef2e730727ff0c8601b062.html 刚开始接触Perl,之前对脚本语言接触的也不多,php也只是略知一二。 最近使用了Perl中的glob函数,觉得真的很神奇。 之前我对于目录中的文件读取操作比较复杂,首先是用opendir打开目录,再用readdir读取目录中的文件。最近在读别人的代码时发现了 glob,最初以为是定义为全局变量的标示符(和局部变量的标示符my有些类似 比如要读取/home/globtest目录中的所有.pl文件,可以这样写: @plFiles
=
glob
'/home/globtest/*.pl'
;
而且可以使用其他的通配符,比如:?,[ ] 看了glob的文档之后,还发现了glob的另一个作用,可以做类似笛卡尔积的操作。 比如文档中的例子是
把@many数组输出就能看到会显示:
对于多组{ }也是可以支持的,我测试了
得到了预想中的结果。 在测试中我发现glob对于空白符的处理有些特殊,而且似乎用转义字符时也会有问题。 具体的原因应该在平时使用glob时会慢慢的了解吧~ 下面是Perl中关于Glob的文档: glob In list context,returns a (possibly empty) list of filename expansions on the value of EXPR such as the standard Unix shell /bin/csh would do. In scalar context,glob iterates through such filename expansions,returning undef when the list is exhausted. This is the internal function implementing the Note that If non-empty braces are the only wildcard characters used in the
Beginning with v5.6.0,this operator is implemented using the standard (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |