I have this database, where some logging is stored; This is in 'domainnm', 'container', 'item' and 'value';
This data is queried with my perl script and where I keep stumbling is this issue:
Per container there are two entries for 'item' (it's about memory usage, btw - to keep talk easier): one is CurrentUsage, the other MaxUsage (which is the maximum of memory allocated since running).
So I thought to fetch the results in an array. (fetchall_arrayref({} fyi), and then iterate over this array and create a smart hash. Only, I am lacking in the "smart" department today, sorely lacking.
This is what I came up with:
Code:
sub parse_results($)
{
my $results=shift;
my %onehash;
my $itemkey;
for my $row(@$results)
{
for my $field(keys %$row)
{
if($row->{'item'} eq 'CurrentUsage')
{
$itemkey='current_usage';
}
elsif($row->{'item'} eq 'MaxUsage')
{
$itemkey='max_usage';
}
else
{
$itemkey=$row->{'item'};
}
%onehash->{$row->{'container'}} = (
$itemkey=>$row->{'value'}
);
}
}
print Dumper(\%onehash);
}
This is plainly not doing what I want; I was thinking of a hash (or array, whatever) with fields like this:
container | current_usage | max_usage
Container1 | 12345 | 123456
Container2 | 54321 | 654321
... etc
What am I doing wrong? Perl complains: Using a hash as a reference is deprecated, and Useless use of a constant in void context and Useless use of hash element in void context etc...