[tpm] dereferencing anonymous hashes
Rob Janes
janes.rob at gmail.com
Tue Apr 10 12:00:14 PDT 2007
ooh boy where do i start ...
sub foo {
my $device = {}; # create an anonymous rash
$config{$cfg}{device} = $device; # And stick it to the major
data structure
$$device{$devId}{status) = 'ok'; # fill up the anonymous rash
$$device{$devId}{msgCnt}++;
}
...
our %device; # use strict or else
{ local *device = $config{$cfg}{device}; # an alias just for me
$status = $device{$devId}{status}; # ahh, here it is
}
there you go!
On 4/10/07, adam.prime at utoronto.ca <adam.prime at utoronto.ca> wrote:
>
>
> Do you really want a reference to a reference to a hash here?
>
> $config{$cfg}{device} = \$device;
>
> That looks like the root of the problem to me. should be:
>
> $config{$cfg}{device} = $device;
>
> to work with the rest of your code i'd think, not having tested anything.
>
> Adam
>
>
>
>
>
> Quoting Fulko Hew <fulko.hew at gmail.com>:
>
> > I always seem to have a problem dereferencing anonymous hashes...
> > (a mental block, or I'm just mental!)
> >
> > In a subroutine I create the thing as such:
> >
> > sub foo {
> > my $device = {}; # create an anonymous hash
> > $config{$cfg}{device} = \$device; # And stick it into the major
> > data structure
> >
> > $device{$devId}{status) = 'ok'; # and populate the anonymous
> hash
> > $device{$devId}{msgCnt}++;
> > }
> >
> > Then later on I want to extract the status:
> >
> > my %device = ${$config{$cfg}{device}};
> > $status = $device{$devId}{status};
> >
> > but this isn't quite right. ;-(
> > _______________________________________________
> > toronto-pm mailing list
> > toronto-pm at pm.org
> > http://mail.pm.org/mailman/listinfo/toronto-pm
> >
>
>
>
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/toronto-pm/attachments/20070410/c2aa45b5/attachment.html
More information about the toronto-pm
mailing list