Some pieces of advice:
- Enclose array definitions, etc. in <code>-blocks
- It's not link="", but link => "", or you'll get a syntax error
- Capitalisation increases legibility ;-)
To the code:
#!perl
use strict;
use warnings;
use Data::Dumper;
sub returnParsedRec {
my ($array, $index, $level) = @_;
my $levelhash = {};
my $otherfields;
while ($index < @$array) {
last if ($array->[$index]->{'level'} < $level);
if ($array->[$index]->{'level'} == $level) {
$otherfields = {};
for (keys %{$array->[$index]}) {
$otherfields->{$_} = $array->[$index]->{$_}
unless ($_ eq 'level' or $_ eq 'department');
}
$levelhash->{$array->[$index]->{'department'}}
= [ $otherfields, returnParsedRec($array, $index + 1, $lev
+el + 1) ];
}
++$index;
}
return $levelhash;
}
sub unParseRec {
my ($levelhash, $result, $level) = @_;
my $tmphash;
for (sort keys %$levelhash) {
$tmphash = $levelhash->{$_}->[0];
$tmphash->{'department'} = $_;
$tmphash->{'level'} = $level;
push @$result, $tmphash;
unParseRec($levelhash->{$_}->[1], $result, $level + 1);
}
return $result;
}
sub returnParsed {
return returnParsedRec(shift, 0, 1);
}
sub unParse {
unParseRec(shift, [], 1);
}
my @array = (
{ level => 1,department => 'Office of President', linkdetails => "some
+thing"},
{ level => 2, department => 'Recruiting',linkdetails => "something1" }
+,
{ level => 2, department => 'Software', linkdetails => "something2"},)
+;
my $struct = returnParsed(\@array);
print Dumper($struct);
#print Dumper \@array;
print "\n" . "=" x 70 . "\n\n";
print Dumper(unParse($struct));
Be aware that HTML should not be formatted with spaces, look for lists (<ul>, <ol>, <dl>) and tables.
Hope this helped.
CombatSquirrel.
Entropy is the tendency of everything going to hell. | [reply] [d/l] [select] |