Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: recursively building a hash of arrays of scalars

by Laurent_R (Canon)
on Sep 30, 2015 at 17:13 UTC ( [id://1143440]=note: print w/replies, xml ) Need Help??


in reply to recursively building a hash of arrays of scalars

If I understand correctly, you want to use $destref to modify your hash. Perhaps what you are looking for is illustrated in the following session under the debugger:
DB<1> %testHash =(); DB<2> $hashRef = \%testHash; DB<3> $destref = \${$hashRef->{'a'}}; DB<4> x \%testHash; 0 HASH(0x302ee0c8) 'a' => SCALAR(0x302ee218) -> undef DB<5> $$destref = 42; DB<6> x \%testHash; 0 HASH(0x302ee0c8) 'a' => SCALAR(0x302ee218) -> 42
As you can see, assigning 42 to $$destref does the trick. But is this what you are trying to do? Hum, probably not, because you have here one extra level of indirection that you probably don't want.

So, maybe, you rather want something like this:

DB<1> %testHash =(); DB<2> $destref = \$testHash{'a'} DB<3> x \%testHash; 0 HASH(0x302ee0c8) 'a' => undef DB<4> $$destref = 42; DB<5> x \%testHash; 0 HASH(0x302ee0c8) 'a' => 42
My gut feeling (if I understood correctly) is that this is more probably what you are trying to do.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1143440]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-03-29 13:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found