On my current OS, Linux Mint, the following code works. Note I take the headers from the first line of df and use them. I then have a small abstraction of a name hash to map mount and percent to appropriate fields. I think your list of headers came from another OS than the one you are running on, and that is leading down the wrong path.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
# a couple of headers that vary from df to df
my %name = (
percent => 'Use%',
mount => 'Mounted',
);
# my @headers = qw(name size used free capacity mount);
my @df = `df -k`;
my @headers = split /\s+/, shift @df;
my %devices;
for my $line (@df) {
print $line;
my %info;
@info{@headers} = split /\s+/, $line; # note the hash slice
$info{capacity} = _percentage_to_decimal($info{$name{percent}});
$devices{ $info{$name{mount}} } = \%info;
}
# Change 12.3% to .123
sub _percentage_to_decimal {
my $percentage = shift;
$percentage =~ s{%}{};
return $percentage / 100;
}
print Dumper \%devices;
Cheers,
R.
Pereant, qui ante nos nostra dixerunt!