Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: How might I handle a special tree? (updated)

by LanX (Saint)
on Dec 07, 2014 at 23:02 UTC ( [id://1109502]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How might I handle a special tree?
in thread How might I handle a special tree?

> how could I recognize if current element is a scalar or another list to recurse?

with ref

> What is missing in this structure is theplaceholder, which will have a group name... 

No idea what you may mean...

update

Maybe

 [ {A => [1, {B => [2,3,4]} ,5, {C => [ 6, { D => [7,8,9] } ] } ]

? ? ?

(untested)

update

TIMTOWTDI

Instead of a one element hash you could use a 2 element array.

Or put the "placeholder" into the sub array as first element.

I personally prefer the hash solution for readability, but keep in mind that keys are stringified.

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)

Replies are listed 'Best First'.
Re^4: How might I handle a special tree?
by vitoco (Hermit) on Dec 07, 2014 at 23:34 UTC

    Thanks for ref. I missed that ;-)

    Your latest structure example looks nice, but I think it would complicate the search and replace algorithms, more than what BrowserUk said.

    I think I'll stay with my AoA proposal, with the first element as the group name (adding a null or "root" element to the original list).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 14:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found