Something like this maybe?
use strict; use warnings; my @iostat_system = qx(iostat -x -p -k -d); my @colnames; my $ncols=0; my %disk_data; foreach my $io (@iostat_system) { chomp $io; # print $io."\n"; my @cols=split(' ',$io); next unless ($io); # if ($cols[0]=~/^device/i) { # what if the device is named device? if ($ncols==0 && $cols[0]=~/^device/i) { @colnames=map {$_=~s/[^a-zA-Z0-9]//g;$_} @cols; $ncols=-1+scalar(@colnames); # print join(' ',@colnames)."\n"; } elsif($ncols>0) { my $dev=$cols[0]; for my $i (1..$ncols) { $disk_data{$dev}{$colnames[$i]}=$cols[$i] +;} } } # use Storable; i dont need this !!!! use Data::Dumper; $Data::Dumper::Deepcopy=1; $Data::Dumper::Purity=1; $Data::Dumper::Sortkeys=1; $Data::Dumper::Indent=2; print Dumper(%disk_data);
edit:dropped storable
edit:fix case of device named device
In reply to Re: Proper way to work with columns
by huck
in thread Proper way to work with columns
by nikita.af
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |