in reply to Proper way to work with columns
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Proper way to work with columns
by nikita.af (Acolyte) on Dec 28, 2016 at 09:34 UTC | |
by huck (Prior) on Dec 28, 2016 at 10:54 UTC | |
by nikita.af (Acolyte) on Dec 28, 2016 at 11:17 UTC |