I plead "insufficient data" to solve your problem. There's too much left out of the code. Let me comment on the code to indicate why I think so. In what follows, I have adjusted the indentation to match what I'm used to. It helps me to understand the flow.
################## sub reordermenu { ################## accesscheck(); @menuitems = Cobra::chomp_database("$datadir/defaults/menu.dat", "0" +); open (DATABASE,"<$datadir/defaults/menu.dat"); hold (DATABASE); @menuitems = <DATABASE>; release (DATABASE); close (DATABASE);
There's a lot missing here. access_check(), hold() and release() all seem to have obvious meanings, but what the heck does Cobra::chomp_database() do in relation to what follows? It probably doesn't matter, though.
MENUITEM: for ($ndx=0; $ndx<= $#menuitems; $ndx++) { ($fid,$fmenu_type,$fmenu_show,$fmenu_filename, $fmenu_name,$fmenu_icon)=split(/\|/,$menuitems[$ndx]); if ($fid eq $info{'m_id'}) { last MENUITEM; } }
The MENUITEM label is superfluous, since there's only the one loop. The if block could be recast in typical Perl postfix style as:
last if ($fid eq $info{'m_id'});
Next we have:
$swap=false; if ($m_action eq "moveup" && $ndx != 0) { $tondx = $ndx - 1; $swap=true; } elsif ($m_action eq "movedown" && $ndx != $#menuitems) { $tondx = $ndx + 1; $swap=true; }
OK, where does "$m_action" come from? Do we really just swap once in this sub? Are you loading the entire database and saving it for just one swap? Something seems to be missing.

In reply to Re: Re-ordering items by $id from a flat file by hbo
in thread Re-ordering items by $id from a flat file by Migey

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.