0
如果存在並將其他數據存儲到數組,則嘗試跳過/ proc /分區文件中/ dev/raw文件中的所有設備。所以,我有如下代碼塊:在模式匹配中使用未初始化的值(m //)
sub get_proc_partitions {
my ($self, $device_name) = @_;
my @partitions;
open(PART, "/proc/partitions") || die "can't open /proc/partitions: $!";
while (<PART>) {
my @field = split;
# Skip this line if the fourth field starts with 'ram'
next if $field[3] =~ /^ram/;
# this regex matches lines like the following.
# in this example it will capture hdb
# 3 64 78150744 hdb 157 735 2168 1720 1745 437 17432
if (/^\s*(?:\d+\s+){3}(\S+)\s.*/) {
my $part = $1;
if (defined $device_name) {
push(@partitions, $part) if ($part =~ /$device_name/);
} else {
push(@partitions, $part);
}
}
}
close(PART);
return \@partitions;
}
而這個代碼將返回我這樣一個錯誤:
Use of uninitialized value in pattern match (m//) at <filename> line 928, <PART> line 2
而此行是指:
next if $field[3] =~ /^ram/;
有可能是文件中的空行,然後現場#4不會如果你是在Linux上,像[Linux的::信息:: DiskStats(HTTPS定義 –
。 org/pod/Linux :: Info :: DiskStats)可能會有用。 – ThisSuitIsBlackNot