[Israel.pm] Hash cleanup

Berler Chanan bc.other at gmail.com
Sun Mar 29 09:27:03 PDT 2009

PS: should I use delete instead of undef ? assuming use delete when looping the keys of keys

-----Original Message-----
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf Of Berler Chanan
Sent: Sunday, March 29, 2009 7:25 PM
To: 'Perl in Israel'
Subject: [Israel.pm] Hash cleanup

Hi All,

I have a global hash variable which look more like this:

$sla_output{host}{Monitor}{service}{CPU}{total_SLA_UP} = 100;
$sla_output{host}{Monitor}{service}{CPU}{total_SLA_DOWN} = 100;
$sla_output{host}{Monitor}{service}{CPU}{total_SLA_DOWNTIME} = 100;
$sla_output{host}{Monitor}{service}{MEM}{total_SLA_UP} = 100;
$sla_output{host}{Monitor}{service}{MEM}{total_SLA_DOWN} = 100;
$sla_output{host}{Monitor}{service}{MEM}{total_SLA_DOWNTIME} = 100;
$sla_output{host}{win9x}{service}{TEMP}{total_SLA_UP} = 100;
$sla_output{host}{ win9x}{service}{TEMP}{total_SLA_DOWN} = 100;
$sla_output{host}{ win9x}{service}{TEMP}{total_SLA_DOWNTIME} = 100;
$sla_output{host}{ win9x }{service}{DISKSPACE}{total_SLA_UP} = 100;
$sla_output{host}{ win9x }{service}{DISKSPACE}{total_SLA_DOWN} = 100;
$sla_output{host}{ win9x }{service}{DISKSPACE}{total_SLA_DOWNTIME} = 100;

(Please I beg you, don't ask why global – legacy issues)
(owh, and lazy me, not all services has 100%...but I am tired of changing the values…☺)

My question: 
Since I am looping each time with different hostgroups (each hostgroup has a list members of hosts – see nagios).
I need to do a mass clean up of this hash (I should have used mess, totally I will agree).
Q: how can I do that ? 
    Should I use undef(%sla_output) ??! I am not sure (would have guessed otherwise)
   Should I look the keys, and loop the keys of keys and do undef for each and one of the keys ? I am not sure either
   Which course should I use ? should I act otherwise if I got same structure but one of the keys of keys is a hash_ref to an array
  (although this is not the case, I do have same kind of structure with hash ref to an array, and I wonder if it leaves any memory leaks)


Perl mailing list
Perl at perl.org.il
No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 8.0.238 / Virus Database: 270.11.31/2028 - Release Date: 03/28/09 07:16:00

More information about the Perl mailing list