存在する場合、/ proc/partitionsファイル内の/ 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
そして、この行が参照:私はcat /proc/partitions
を発行すると
next if $field[3] =~ /^ram/;
ファイル内の空行があるかもしれません、そしてフィールド#4が –
に定義されることはありません。 org/pod/Linux :: Info :: DiskStats)が役に立つかもしれません。 – ThisSuitIsBlackNot