Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Arbitrarily Nested HoH

by apomatix (Novice)
on Oct 15, 2010 at 02:31 UTC ( [id://865382]=note: print w/replies, xml ) Need Help??


in reply to Arbitrarily Nested HoH

I like your solution. I wonder how else you thought of doing it. However, I don't think your solution would be easy for someone "just learning Perl".

Replies are listed 'Best First'.
Re^2: Arbitrarily Nested HoH
by Limbic~Region (Chancellor) on Oct 15, 2010 at 21:26 UTC
    apomatix,
    I wonder how else you thought of doing it.

    As I indicated, I considered an iterator. Here is a very unpolished working version:

    As you can see, it is far more complex than the recursive solution. Also, the iterator could result in bizarre behavior if the hash isn't walked all at once. This is because each itself is an iterator that is reset any time there is a call to keys or values. In the recursive version, the hash is traversed all at once so there isn't an opportunity to reset the iterator mid-traversal.

    Here is the stack based iterative version I was thinking of. I think it is the nicest because it is how my brain works:

    However, I don't think your solution would be easy for someone "just learning Perl".

    Why? That's an honest question. Provided you understand references (which he does), it should be straight forward. That is unless you are like me and have a hard time thinking recursively but the whole point of writing it recursively was that most programmers I know think that way naturally. What about it do you think a seasoned C++ programmer would find hard to understand?

    Cheers - L~R

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 18:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found