http://qs321.pair.com?node_id=559194


in reply to Re: tree-oriented query against table-oriented data
in thread tree-oriented query against table-oriented data

i guess, this will not exist, because it is actually a combination of querying data from a database and displaying the result.

That is one way of evaluating the problem, however it is possible to 'rethink' the situation if you strip away pre-existing paradigms, methodologies, and ask the following:

Given this:

sitcom/simpsons/homer/simpson sitcom/simpsons/ned/flanders sitcom/flintstones/fred/flintstone sitcom/flintstones/wilma/flintstone sitcom/flintstones/barney/rubble gameshow/price is right/bob/barker gameshow/jeopardy/alex/trebek

What can I use to transform it into this?:

$dataroot = { 'gameshow' => { 'price is right' => [ { 'lname' => 'barker', 'fname' => 'bob' } ], 'jeopardy' => [ { 'lname' => 'trebek', 'fname' => 'alex' } ] }, 'sitcom' => { 'simpsons' => [ { 'lname' => 'simpson', 'fname' => 'homer' }, { 'lname' => 'flanders', 'fname' => 'ned' } ], 'flintstones' => [ { 'lname' => 'flintstone', 'fname' => 'fred' }, { 'lname' => 'flintstone', 'fname' => 'wilma' }, { 'lname' => 'rubble', 'fname' => 'barney' } ] } };

The key consideration here is a simple question of transforming the flat 'row-based' representation into a 'nested representation'. This does not necessarily involve a database at all. Nor does it necessarily involve 'displaying' anything (unless you count using Data::Dumper to show the output for illustrative purposes only).

=oQDlNWYsBHI5JXZ2VGIulGIlJXYgQkUPxEIlhGdgY2bgMXZ5VGIlhGV