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

前端之家收集整理的这篇文章主要介绍了Perl学习笔记(5)glob的使用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
######################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 "\0" 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:\\home\\globtest"); @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

猜你在找的Perl相关文章