I wrote a utility awhile back that gives me DBA info using Informix onstat commands. The following is the onstat –g ses command, which I want to see sorted 4 different ways.
So I created 4 hashes. I’m not familiar with complex data structures because I taught myself Perl, and I’m not there yet. I haven’t used array of hashes, anonymous data types, etc yet, but would like to learn.
Since all 4 hashes contain the exact same info but different keys, I’m sure there is a better way to do this. What do ya’ll think is a better way?
So I created 4 hashes. I’m not familiar with complex data structures because I taught myself Perl, and I’m not there yet. I haven’t used array of hashes, anonymous data types, etc yet, but would like to learn.
Since all 4 hashes contain the exact same info but different keys, I’m sure there is a better way to do this. What do ya’ll think is a better way?
Code:
@input = (
'onstat headers ....',
'3214 informix - 0 - 0 12288 11384 off',
'3211 sifagent IISD-SIF 8072 10.37.11 1 86016 52368 off',
'3209 sifagent IISD-SIF 4880 10.37.11 1 90112 52392 off',
'3203 tblough 22 106643 irv001 1 475136 446688 off',
'3101 dwilliam 5 86562 irv001 1 1155072 1100144 off',
'3100 dwilliam 5 86329 irv001 1 282624 263424 off',
'3040 adavila 10 76856 irv001 1 2490368 2440584 off',
);
foreach (@input) {
next unless /^\d/;
my (@field) = split;
my $sid = ' ' x ( 8 - length($field[0])) . $field[0];
my $username = $field[1] . ' ' x ( 8 - length($field[1]));
my $tty = $field[2] . ' ' x ( 8 - length($field[2]));
my $pid = $field[3] . ' ' x ( 8 - length($field[3]));
my $memory = ' ' x (12 - length($field[6])) . $field[6];
$SID{$sid} = "$sid $username $tty $pid $memory\n";
$Memory{"$memory $sid"} = "$sid $username $tty $pid $memory\n";
$User{"$username $sid"} = "$sid $username $tty $pid $memory\n";
$PID{$pid} = "$sid $username $tty $pid $memory\n";
}
print "$SID{$_}" foreach (sort keys %SID);