[thelist] Re: Trying to use hash with non-const name

Simon Oliver simon.oliver at umist.ac.uk
Wed May 1 10:26:01 CDT 2002


You could store your hashes within a hash:

my %hashes = (
  DpInfoOperation => {
    Net =>2,
    Retrain  =>2,
    BER   =>3,
  },
  CpuOperation => {
    High=>1,
    Low=>2,
};

       if ($file =~/$FileName/i)
       {
        $tmp = $FileName.Operation;
        $Operation = $hashes{$tmp};
         last;
       }

Now $Operation contains a reference to the appropriate hash (assuming $tmp
eq one of the keys of %hashes).  So when accessing the hash you need to
dereference:

keys(%Operation) becomes keys(%$Operation)

and

$Operation{$Opp} becomes $Operation->{$Opp}

--
  Simon Oliver



More information about the thelist mailing list