jasonl has asked for the wisdom of the Perl Monks concerning the following question:
Using Net::LDAP, I'm running into a problem trying to deal with multiple instances of an attribute. It appears that they get stored in a hash as an array of arrays; in the initial hash ($valref), I can dump the values like this:
@pktClassList = @$valref{packetclassifierlist}; print "class = "; foreach my $i (@pktClassList) { foreach my $j (@$i) { print "$j\n"; } }
Unfortunately I need to get @pktClassList to another sub as a member of a different hash. I'm assigning it to the hash in a switch statement like this:
... case /packetclassifierlist/ { $tlvHash{pktClassList} = "@pktClassLi +st" } ...
I then pass $tlvHash to my new sub as "newSub($tlv,%tlvHash);". In newSub I'm doing this:
... my ($tlv, %tlvHash) = @_; ... my $classArray = $tlvHash{pktClassList}; foreach my $i (@$classArray) { print "i = $i\n"; foreach my $j (@$i) { print "j = $j\n"; } }
I've tried various permutations of @, $, and @$ around classArray and tlvHash, but if the code executes at all, the best I get is "Can't use string ("ARRAY(0xa3f6e4)") as an ARRAY ref while "strict refs" in use...." I'm really trying to stick with packing this into %tlvHash instead of passing it as a separate arg, because multiple functions are calling newSub and they won't all have this attribute.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: problems dereferencing an array of arrays as a hash value
by gmargo (Hermit) on Nov 23, 2009 at 16:54 UTC | |
by jasonl (Acolyte) on Nov 23, 2009 at 17:14 UTC | |
by gmargo (Hermit) on Nov 23, 2009 at 17:42 UTC | |
|
Re: problems dereferencing an array of arrays as a hash value
by toolic (Bishop) on Nov 23, 2009 at 16:54 UTC | |
by Anonymous Monk on Nov 24, 2009 at 10:23 UTC |