Some pieces of advice: 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.

In reply to Re: Re: Re: Logic for sorting of this given array by CombatSquirrel
in thread Logic for sorting of this given array by ravish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.