dragonchild has asked for the wisdom of the Perl Monks concerning the following question:
and convert it into:$start = { 'lineitem' => { 'invoice' => 1 }, 'market_x_branch' => { 'insurer' => 1 }, 'invoice' => { 'lineitem' => 1 }, 'insurer' => { 'market_x_branch' => 1 } };
$end = [ [ 'lineitem', 'invoice' ], [ 'market_x_branch', 'insurer' ] ];
Now, I've got code that will pass that test. That code is:
foreach my $x (keys %$start) { next unless exists $start->{$x}; my @values = ($x, keys %{$start->{$x}}); push @$end, \@values; delete $start->{$_} for @values; }
The problem is that the following test is failing and I simply cannot wrap my head around it.
$start = { 'lineitem' => { 'invoice' => 1 }, 'invoice' => { 'lineitem' => 1, 'claim' => 1 }, 'insurer' => { 'claim' => 1 }, 'claim' => { 'invoice' => 1, 'insurer' => 1 } }; $end = [ [ 'invoice', 'claim', 'insurer', 'lineitem', ], ];
The order of the elements in $end and the sub-arrays in $end is completely unimportant, as I'm treating it as a set, not a list.
Any suggestions at all would be greatly appreciated.
Update: Added the code I'm using.
------
We are the carpenters and bricklayers of the Information Age.
Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reducing HoH to AoA
by kvale (Monsignor) on Apr 01, 2004 at 16:23 UTC | |
by dragonchild (Archbishop) on Apr 01, 2004 at 16:35 UTC | |
|
Re: Reducing HoH to AoA
by ccn (Vicar) on Apr 01, 2004 at 17:02 UTC | |
|
Re: Reducing HoH to AoA
by calin (Deacon) on Apr 01, 2004 at 17:37 UTC | |
|
Re: Reducing HoH to AoA
by Limbic~Region (Chancellor) on Apr 01, 2004 at 16:16 UTC | |
by dragonchild (Archbishop) on Apr 01, 2004 at 16:18 UTC | |
by Limbic~Region (Chancellor) on Apr 01, 2004 at 16:38 UTC |