- 论坛徽章:
- 0
|
获取指定目录下的所有文件后放到数组中,让后通过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
|
|