Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Re: Adding additional values to a hash of an hash ?

by gnangia (Scribe)
on Nov 12, 2002 at 20:05 UTC ( [id://212384]=note: print w/replies, xml ) Need Help??


in reply to Re: Adding additional values to a hash of an hash ?
in thread Adding additional values to a hash of an hash ?

Unfotunately it won't work for me. I saw some code pasted on one of the posts as follows
push (@{$data{$formname}}, { 'type' => "select", 'field_name' => $selectname, 'value' => $attr->{'value'}

This would work for me but I don't know how to access the information. It seems like its being pushed into an array where the arrayname is the hash{key} ? How would one access this info? If I can get the answer to this, then I believe I am all set.

Replies are listed 'Best First'.
Re: Re: Re: Adding additional values to a hash of an hash ?
by djantzen (Priest) on Nov 12, 2002 at 20:21 UTC

    What you're talking about then is a hash of arrays of hashes. $data{$formname} now returns a reference to the array, and to access an individual hash table in the array you can say something like: $data{$formname}->[0]{type}. Basically, what you're doing is a hash lookup to grab the array reference pointed to by $formname, then using an array index to obtain a reference to the nested hash whose data you need to access, and then doing a normal hash lookup there on 'type'.

Re: Re: Re: Adding additional values to a hash of an hash ?
by robartes (Priest) on Nov 12, 2002 at 20:21 UTC
    Hi gnangia,

    the code above uses a hash slice (hence the @) to assign a value to the key $formname. The value happens to be an anonymous hash, with keys 'type', 'field_name' and 'value', and corresponding values. What happens is that a reference to said anonymous hash is pushed onto the hash slice. To access fields in this anon hash, use code such as:

    $data{$formname}->{'type'};
    or:
    $data{$formname}{'type'};
    Note that the above is untested and may not work (particularly the top example might need some more curlies).

    Update: Never mind my rambling, I missed a pair of parentheses in your code. fever is correct in what the code is and how you access fields in it. I really must get some more sleep, or less cafeine, or both. I thought pushing stuff onto a hash slice sounded weird when I wrote it :)

    CU
    Robartes-

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 02:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found