Index: trunk/klask
===================================================================
--- trunk/klask	(revision 10)
+++ trunk/klask	(revision 11)
@@ -13,23 +13,23 @@
 # libcrypt-des-perl libcrypt-hcesha-perl   libdigest-hmac-perl
 
-our $KLASK_DB  = '/var/cache/klask/klaskdb';
-our $KLASK_SW  = '/var/cache/klask/switchdb';
-our $KLASK_CFG = '/etc/klask.conf';
-
-my $switchdb = YAML::LoadFile("$KLASK_CFG");
-
-our %default = %{$switchdb->{default}};
-our @switch  = @{$switchdb->{switch}};
-
-our %switch_level = ();
+my $KLASK_DB  = '/var/cache/klask/klaskdb';
+my $KLASK_SW  = '/var/cache/klask/switchdb';
+my $KLASK_CFG = '/etc/klask.conf';
+
+my $SWITCH_DB = YAML::LoadFile("$KLASK_CFG");
+
+my %DEFAULT = %{$SWITCH_DB->{default}};
+my @SWITCH  = @{$SWITCH_DB->{switch}};
+
+my %switch_level = ();
 LEVEL_OF_EACH_SWITCH:
-for my $sw (@switch){
-   $switch_level{$sw->{hostname}} = $sw->{level} || $default{switch_level}  || 2;
-   }
-@switch  = sort { $switch_level{$b->{hostname}} <=> $switch_level{$a->{hostname}} } @{$switchdb->{switch}};  
-
-our %switch_port_count = ();
-
-our %cmddb = (
+for my $sw (@SWITCH){
+   $switch_level{$sw->{hostname}} = $sw->{level} || $DEFAULT{switch_level}  || 2;
+   }
+@SWITCH = sort { $switch_level{$b->{hostname}} <=> $switch_level{$a->{hostname}} } @{$SWITCH_DB->{switch}};  
+
+my %switch_port_count = ();
+
+my %CMD_DB = (
    help       => \&cmd_help,
    exportdb   => \&cmd_exportdb,
@@ -47,5 +47,5 @@
    );
 
-our %INTERNALPORTMAP = (
+my %INTERNAL_PORT_MAP = (
    0 => 'A',
    1 => 'B',
@@ -57,5 +57,5 @@
    7 => 'H',
    );
-our %INTERNALPORTMAPREV = reverse %INTERNALPORTMAP;
+my %INTERNAL_PORT_MAP_REV = reverse %INTERNAL_PORT_MAP;
 
 
@@ -64,11 +64,11 @@
 ################
 
-my $cmd = shift || 'help';
-if (defined $cmddb{$cmd}) {
-   $cmddb{$cmd}->(@ARGV);
+my $cmd = shift @ARGV || 'help';
+if (defined $CMD_DB{$cmd}) {
+   $CMD_DB{$cmd}->(@ARGV);
    }
 else {
    print STDERR "klask: command $cmd not found\n\n";
-   $cmddb{help}->();
+   $CMD_DB{help}->();
    exit 1;
    }
@@ -168,9 +168,9 @@
 
    INIT_EACH_SWITCH:
-   for my $sw (@switch) {
+   for my $sw (@SWITCH) {
 #print "$sw->{hostname} \n";
       my %session = ( -hostname   => $sw->{hostname} );
          $session{-version} = $sw->{version}   || 1;
-         $session{-port}    = $sw->{snmpport}  || $default{snmpport}  || 161;
+         $session{-port}    = $sw->{snmpport}  || $DEFAULT{snmpport}  || 161;
          if (exists $sw->{version} and $sw->{version} eq 3) {
             $session{-username} = $sw->{username} || 'snmpadmin';
@@ -181,5 +181,5 @@
             }
          else {
-            $session{-community} = $sw->{community} || $default{community} || 'public';
+            $session{-community} = $sw->{community} || $DEFAULT{community} || 'public';
             }
 
@@ -189,7 +189,7 @@
 #         -hostname   => $sw->{hostname},
 #         -version    => $sw->{version}   || 1,
-#         -community  => $sw->{community} || $default{community} || 'public',
+#         -community  => $sw->{community} || $DEFAULT{community} || 'public',
 #         -username   => $sw->{username}  || 'snmpadmin',
-#         -port       => $sw->{snmpport}  || $default{snmpport}  || 161,
+#         -port       => $sw->{snmpport}  || $DEFAULT{snmpport}  || 161,
 #         );
 #         if (exists $sw->{version} and $sw->{version} eq 3) {
@@ -252,9 +252,9 @@
    return %ret if $arp eq 'unknow';;
 
-   my @switch_search = @switch;
+   my @SWITCH_search = @SWITCH;
    if ($switch_proposal ne '') {
-      for my $sw (@switch) {
+      for my $sw (@SWITCH) {
          next if $sw->{hostname} ne $switch_proposal;
-         unshift @switch_search, $sw;
+         unshift @SWITCH_search, $sw;
          last;
          }
@@ -264,10 +264,10 @@
    
    LOOP_ON_SWITCH:
-   for my $sw (@switch_search) {
+   for my $sw (@SWITCH_search) {
       my ($session, $error) = Net::SNMP->session( %{$sw->{local_session}} );
 print "$error \n" if $error;
 #         -hostname   => $sw->{hostname},
-#         -community  => $sw->{community} || $default{community} || 'public',
-#         -port       => $sw->{snmpport}  || $default{snmpport}  || 161
+#         -community  => $sw->{community} || $DEFAULT{community} || 'public',
+#         -port       => $sw->{snmpport}  || $DEFAULT{snmpport}  || 161
 #         );
 #print "$sw->{hostname} --  $research \n";
@@ -323,5 +323,5 @@
    return $ret if $arp eq 'unknow';
 
-   for my $sw (@switch) {
+   for my $sw (@SWITCH) {
       $switch_port_count{$sw->{hostname}} = {} if not exists $switch_port_count{$sw->{hostname}};
 #      $sw->{_port} = {} if not exists $sw->{_port};
@@ -331,10 +331,10 @@
 #print " $arp -> $research\n";
    LOOP_ON_ALL_SWITCH:
-   for my $sw (@switch) {
+   for my $sw (@SWITCH) {
       my ($session, $error) = Net::SNMP->session( %{$sw->{local_session}} );
 print "$error \n" if $error;
 #         -hostname   => $sw->{hostname},
-#         -community  => $sw->{community} || $default{community} || 'public',
-#         -port       => $sw->{snmpport}  || $default{snmpport}  || 161
+#         -community  => $sw->{community} || $DEFAULT{community} || 'public',
+#         -port       => $sw->{snmpport}  || $DEFAULT{snmpport}  || 161
 #         );
 #print "$sw->{hostname} --  $research \n";
@@ -366,5 +366,5 @@
 sub get_list_network {
 
-   return keys %{$switchdb->{network}};
+   return keys %{$SWITCH_DB->{network}};
    }
 
@@ -372,5 +372,5 @@
    my $network = shift;
 
-   return $switchdb->{network}{$network}{interface};
+   return $SWITCH_DB->{network}{$network}{interface};
    }
   
@@ -383,5 +383,5 @@
 
    for my $net (@network) {
-      my @line  = @{$switchdb->{network}{$net}{'ip-subnet'}};
+      my @line  = @{$SWITCH_DB->{network}{$net}{'ip-subnet'}};
       for my $cmd (@line) {
          for my $method (keys %$cmd){
@@ -411,5 +411,5 @@
 
    for my $net (@network) {
-      push @res, $switchdb->{network}{$net}{'main-router'};
+      push @res, $SWITCH_DB->{network}{$net}{'main-router'};
       }
 
@@ -426,5 +426,5 @@
    my $major = int( ($port - 1) / 8 );
 
-   return "$INTERNALPORTMAP{$major}$reste";
+   return "$INTERNAL_PORT_MAP{$major}$reste";
    }
 
@@ -441,5 +441,5 @@
    my $reste =  substr($port, 1);
    
-   return $INTERNALPORTMAPREV{$letter} * 8 + $reste;
+   return $INTERNAL_PORT_MAP_REV{$letter} * 8 + $reste;
    }
 
@@ -722,5 +722,5 @@
   
       my $sw_location = '';
-      for my $sw (@switch) {
+      for my $sw (@SWITCH) {
          next if $sw_hostname ne $sw->{hostname};
          $sw_location = $sw->{location};
@@ -767,6 +767,6 @@
    DETECT_ALL_ROUTER:
 #   for my $one_computer ('194.254.66.254') {
-   for my $one_computer ( get_list_main_router(get_list_network()) ) {
-      my %resol_arp = resolve_ip_arp_host($one_computer,'*','low');            #resolution arp
+   for my $one_router ( get_list_main_router(get_list_network()) ) {
+      my %resol_arp = resolve_ip_arp_host($one_router,'*','low');            #resolution arp
       next DETECT_ALL_ROUTER if $resol_arp{mac_address} eq 'unknow';
       
@@ -802,5 +802,5 @@
    my @list_switch_ip = ();
    my @list_switch_ipv4 = ();
-   for my $sw (@switch){
+   for my $sw (@SWITCH){
       push @list_switch_ip, $sw->{hostname};
       }
@@ -1000,5 +1000,5 @@
       
    my %db_building= ();
-   for my $sw (@switch) {
+   for my $sw (@SWITCH) {
       my ($building, $location) = split /\//, $sw->{location}, 2;
       $db_building{$building} ||= {};
