标题: perl 读目录下文件问题,请教如何略过“点”文件 [打印本页] 作者: huagao2000 时间: 2012-11-26 11:00 标题: perl 读目录下文件问题,请教如何略过“点”文件 目录下只有一个文件:
[laps0@localhost ~]$ ls -a data/rawdata/profile/from_liju/hd
. .. 20100701.TXT
代码如下:
#!/usr/bin/perl
my $path="/home/laps0/data/rawdata/profile/from_liju/hd";
opendir(DIR,$path) or die " Error : can't open $path !";
my $file;
while ($file=readdir DIR)
{
print "the file is : $file \n";
open(FILE,"$file"
my @var = <FILE>;
print "the var is : $var[25] \n";
close(FILE);
输出信息:
[laps0@localhost wind]$ perl tmp.pl
the file is : .
the var is :
the file is : 20100701.TXT
the var is :
the file is : ..
the var is :
问题是不想出来那两个点文件,请问如何操作,请费心指教,谢谢!
作者: xi0ws 时间: 2012-11-26 11:15
next if ($file eq "."|| $file eq "..");
复制代码
作者: 首天 时间: 2012-11-26 11:16
#!/usr/bin/perl
my $path="/home/laps0/data/rawdata/profile/from_liju/hd";
opendir(DIR,$path) or die " Error : can't open $path !";