[tpm] dereferencing anonymous hashes

Uri Guttman uri at stemsystems.com
Tue Apr 10 14:32:52 PDT 2007


>>>>> "FH" == Fulko Hew <fulko.hew at gmail.com> writes:

  FH> because what fixed my problem was (transcribing correctly this time):

  FH> my %device = {};

that is STILL wrong. please enable warnings and it will barf out that
you are assigning an odd number of elements to a hash.

perl -lwe '%x = {}'
Name "main::x" used only once: possible typo at -e line 1.
Reference found where even-sized list expected at -e line 1.

hey, it is even more informative than it used to be.


  FH> $config{$cfg}{device} = \%device;
  FH> $device{$devid}{status} = 'OK';

you still have a hash ref as a key in %device. print it out with
Data::Dumper to see it.

  FH> ...

  FH> my %device = %{$config{$cfg}{device}};

that is doing a complete shallow copy of a hash. it will wipe out your
broken initializer (which you think is a clearing operation).

  FH> $status = $device{$devId}{status};

$devId is not the same as $devid. spelling matters in perl. if you
used strict you would have been told about that error.

uri

-- 
Uri Guttman  ------  uri at stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


More information about the toronto-pm mailing list