#!/usr/bin/perl -w use strict; my $rdb={ 'table a' => { 'aa' => { data => { key1=>'val', key3=>'val',key2=>'val', }, parent => '', children => { 'table b' => { 'ab' => "TBD", }, 'table c' => { 'ac' => "TBD", }, } }, 'ba' => { data => { key1=>'val', key3=>'val',key2=>'val', }, parent => '', children => { 'table b' => { 'bb' => "TBD", }, 'table c' => { 'bc' => "TBD", }, } }, }, 'table b' => { 'ab' => { data => { nonsense => 'foo' }, parent => 'aa', children => {}, }, 'bb' => { data => { morenonsense => 'foo' }, parent => 'bb', children => {}, }, }, 'table c' => { 'ac' => { data => { keyi => 'val' }, parent => 'aa', children => { 'table d' => { 'ae' => "TBD", 'af' => "TBD", }, 'table e' => { 'ag' => "TBD", }, }, }, 'bc' => { data => { keyi => 'val' }, parent => 'bb', children => { 'table d' => { 'be' => "TBD", 'bf' => "TBD", }, 'table e' => { 'bg' => "TBD", 'bh' => "TBD", }, }, }, }, 'table d' => { 'ae' => { data => { k => 'v', k2 => 'v', k3 => 'v' }, parent => 'ac', children => {}, }, 'af' => { data => { k => 'x', k2 => 'x', k3 => 'x' }, parent => 'ac', children => {}, }, 'be' => { data => { k => 'v', k2 => 'v', k3 => 'v' }, parent => 'bc', children => {}, }, 'bf' => { data => { k => 'x', k2 => 'x', k3 => 'x' }, parent => 'bc', children => {}, }, }, 'table e' => { 'ag' => { data => { f => 'b', b => 'k' }, parent => 'ac', children => {}, }, 'bg' => { data => { f => 'b', b => 'k' }, parent => 'bc', children => {}, }, 'bh' => { data => { f => 'b', b => 'k' }, parent => 'bc', children => {}, }, } }; # Fixes the "TBD" above $rdb->{'table c'}->{ac}->{children}->{'table d'}->{ae}= $rdb->{'table d'}->{ae}; $rdb->{'table c'}->{ac}->{children}->{'table d'}->{af}= $rdb->{'table d'}->{af}; $rdb->{'table c'}->{ac}->{children}->{'table e'}->{ag}= $rdb->{'table e'}->{ag}; $rdb->{'table a'}->{aa}->{children}->{'table b'}->{ab}= $rdb->{'table b'}->{ab}; $rdb->{'table a'}->{aa}->{children}->{'table c'}->{ac}= $rdb->{'table c'}->{ac}; $rdb->{'table c'}->{bc}->{children}->{'table d'}->{be}= $rdb->{'table d'}->{be}; $rdb->{'table c'}->{bc}->{children}->{'table d'}->{bf}= $rdb->{'table d'}->{bf}; $rdb->{'table c'}->{bc}->{children}->{'table e'}->{bg}= $rdb->{'table e'}->{bg}; $rdb->{'table c'}->{bc}->{children}->{'table e'}->{bh}= $rdb->{'table e'}->{bh}; $rdb->{'table a'}->{ba}->{children}->{'table b'}->{bb}= $rdb->{'table b'}->{bb}; $rdb->{'table a'}->{ba}->{children}->{'table c'}->{bc}= $rdb->{'table c'}->{bc}; # Given $rdb and the key "table a", traverse the structures # so that you produce the records of: # # aa ab ac ag ae # aa ab ac ag af # ba bb bc bg be # ba bb bc bg bf # ba bb bc bh be # ba bb bc bh bf # # (These can be arrays of arrays or arrays of hashes # or arrays of strings or whatever.... # but any column MUST only contain things of the same kind) # # Note that: # * each a record from each table is represented in # each "record" produced # * multiple records within a table are noted once for # each permutation # (ae and af above) # * subsequent table names are not known: you're given # only the first one. # * the keys within the hashes are guaranteed to be # unique. # * the data is not important. # * the keys (aa, ab, bb) follow no set pattern and are # strictly coincidental just in this example. # * each record will join with the proper number of # tables. # * be prepared to have "table a" be the one and only # table (boundaries!) # # NO HARD WIRING, except for the initial table name. # # [I think I keyed these tables in right.]