Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: dereferencing multiple hash array structure

by Athanasius (Archbishop)
on Jun 23, 2012 at 03:40 UTC ( [id://977933]=note: print w/replies, xml ) Need Help??


in reply to dereferencing multiple hash array structure

Here is an extract from the data structure in DoxyDocs1.pm, re-formatted for greater readability and with one => re-written as quote + comma (see Comma Operator in perlop):

detailed => { doc => [ { type => 'text', content => 'Add a child to the container ' }, "params", [ { parameters => [ { name => 'child' } ], doc => [ { type => 'text', content => 'is the child element to add' } ] } ] ] },

As you can see, doc is a hash key with a reference to an anonymous array as its value. This array contains 3 elements: a reference to an anonymous hash; the string "params"; and a reference to an anonymous array. As GrandFather says, this is syntactically OK, but it is almost certainly not what was intended — which is why you’re unable to extract the data you want. You will need to re-consider the way this data structure is generated.

Update: Using prototypes on subroutines is usually a bad idea, unless you have a strong reason to. Better to remove the trailing parentheses from the definition of sub GenerateClassInfo; then call it without the & prefix.

HTH,

Athanasius <°(((><contra mundum

Replies are listed 'Best First'.
Re^2: dereferencing multiple hash array structure
by AnomalousMonk (Archbishop) on Jun 23, 2012 at 15:13 UTC
    Using prototypes on subroutines is usually a bad idea...

    Further to Athanasius's point: The function  GenerateClassInfo is prototyped to take zero arguments, but is defined as operating on a single argument. The only way this function can work as defined is to defeat the prototyping mechanism by calling the function with the  & sigil. But what's the point of all that? Wasted motion of that sort is one of the reasons prototypes have a bad reputation. For far more, see Far More than Everything You've Ever Wanted to Know about Prototypes in Perl -- by Tom Christiansen. (Update: Furthermore, the  GenerateClassInfo function is called before it is either defined or declared, i.e., before its prototype is available for checking. This would have generated a warning had the function not been called with the  & sigil.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-19 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found