加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Perl学习笔记(5)glob的使用

发布时间:2020-12-16 00:32:23 所属栏目:大数据 来源:网络整理
导读:######################read()函数中的offset参数含义 read (FILEHANBD,$var,$length,$offset) read 函数有四个参数,最容易误解的是$offset 它的含义看官方文档,解释是: An OFFSET may be specified to place the read data at some place in the string o
######################read()函数中的offset参数含义
read (FILEHANBD,$var,$length,$offset)
read 函数有四个参数,最容易误解的是$offset
它的含义看官方文档,解释是:

An OFFSET may be specified to place the read data at some place in the string other than the beginning. A negative OFFSET specifies placement at that many characters counting backwards from the end of the string. A positive OFFSET greater than the length of SCALAR results in the string being padded to the required size with "" bytes before the result of the read is appended.


#####################优化技巧

函数的开销是很大的。 A循环地调用一个函数 B在函数中循环地进行一个操作 从性能上说,B比A好。 #####################glob的用法--读取一个目录下的所有文件 1. 比如要读取/home/globtest目录中的所有文件,可以这样写:@plFiles = glob '/home/globtest/*.*'; 上面的glob的用法相当于如下 opendir(Dir,"/home/globtest");#注意这是在Linux的写法,若在Windows下,应该写为opendir(Dir,"F:homeglobtest"); @Files=readdir(Dir); closedir(Dir); foreach $Cur(@Files){ $File="/home/globtest".$Cur; open(IN,$File); while(<IN>){ ...... ? ? ? ? ? ? ? ? ? ?} close(IN); } 2 .?@many = glob "{apple,tomato,cherry}={green,yellow,red}"; 把@many数组输出就能看到会显示: 1 apple=green 2 apple=yellow 3 apple=red 4 tomato=green 5 tomato=yellow 6 tomato=red 7 cherry=green 8 cherry=yellow 9 cherry=red

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读