免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3068 | 回复: 3
打印 上一主题 下一主题

获取文件夹目录下的问题作为一个变量给open 打开后,运行子程序和预计的不一样? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-01-12 00:13 |只看该作者 |倒序浏览
获取指定目录下的所有文件后放到数组中,让后通过foreach 调用子程序时,运行的结果和单独运行子程序不一样,大侠看看为什么?

my @files=<E:/perld/diag/*.*>;
foreach(@files) {
        chomp($_);
        print "$_\n";
        &getname($_);
        &getcpunum($_);
        &cpuratio($_);
}

Name "main::count" used only once: possible typo at E:\perld\get_perf.pl line 67.
Unsuccessful open on filename containing newline at E:\perld\get_perf.pl line 57.
readline() on closed filehandle CPU at E:\perld\get_perf.pl line 60.
Use of uninitialized value $path in string at E:\perld\get_perf.pl line 77.
readline() on closed filehandle OINTF at E:\perld\get_perf.pl line 79.
Missing argument in printf at E:\perld\get_perf.pl line 88.
Invalid conversion in printf: "%\012" at E:\perld\get_perf.pl line 88.
Unsuccessful open on filename containing newline at E:\perld\get_perf.pl line 57.
readline() on closed filehandle CPU at E:\perld\get_perf.pl line 60.
Use of uninitialized value $path in string at E:\perld\get_perf.pl line 77.
readline() on closed filehandle OINTF at E:\perld\get_perf.pl line 79.
Missing argument in printf at E:\perld\get_perf.pl line 88.
Invalid conversion in printf: "%\012" at E:\perld\get_perf.pl line 88.
Unsuccessful open on filename containing newline at E:\perld\get_perf.pl line 57.
readline() on closed filehandle CPU at E:\perld\get_perf.pl line 60.
Use of uninitialized value $path in string at E:\perld\get_perf.pl line 77.
readline() on closed filehandle OINTF at E:\perld\get_perf.pl line 79.
Missing argument in printf at E:\perld\get_perf.pl line 88.
Invalid conversion in printf: "%\012" at E:\perld\get_perf.pl line 88.

my $file = "E:/perld/diag/v3r1diag.txt";
&getcpunum("$file");
#test code area
## get the cpu num on device ,just test the v3r1-diag,need to test v1r3 and v2r1
sub getcpunum {
#my $path = shift @_;
my $path = shift;
open CPU,"$path";
my @slot;
my $cpunum;
while(<CPU>){
        if ($_ =~ m/^\s*(Slot\s*\d\s*cpu\s*\d)/){
                 push @slot,$1;
                }
        }
my $count;
@slot = grep { ++$count{$_} < 2 } @slot;#reference the internet writen by somone
$cpunum = $#slot+1;
printf "CPU\tNum:%d\n",$cpunum;
close(CPU);
}

运行结果是正确的,但用上面的foreach进行调试的结果为0
CPU        Num:16

论坛徽章:
0
2 [报告]
发表于 2016-01-12 22:38 |只看该作者
不会是这个问题太low了吧,大家不屑于答还是太hight了,答不了。自己先顶起来,自己学perl是工作上的需要,通过perl 有些重复的动作perl就可以替我完成,现在也就下班周末学习下!如果问题太low请大家谅解,perl中也搜索过类似问题,还未找到答案。

论坛徽章:
0
3 [报告]
发表于 2016-01-12 23:56 |只看该作者
貌似发现问题所在了,my @files=<E:/perld/diag/*.*>;  是返回的问题,其实我要的是文件夹下面所有文件的绝对路径+文件名;那问题又来了,怎么把数据中的元素加上绝对路径 后变成一个包含绝对路径+文件名的路径。

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
4 [报告]
发表于 2016-01-13 08:30 |只看该作者
本帖最后由 jason680 于 2016-01-13 08:31 编辑

回复 3# emlin129

    my @files=glob("E:/perld/diag/*.*");




您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP