Greetings Wise Ones,

I'm trying to reorder menu items listed in a flat db file. I am using a similar sub to accomplish this on a different site that works but is configured a bit differently. This one sort of works but is sending the menu item to the absolute top of the list instead of up one id or down one id. Here is the sub with the problem.
################## 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); MENUITEM: for ($ndx=0; $ndx<= $#menuitems; $ndx++) { ($fid,$fmenu_type,$fmenu_show,$fmenu_filename,$fmenu_name,$fme +nu_icon)=split(/\|/,$menuitems[$ndx]); if ($fid eq $info{'m_id'}) { last MENUITEM; } } $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; } if ($swap) { chomp($menuitems[$ndx]); chomp($menuitems[$tondx]); ($fid,$fmenu_type,$fmenu_show,$fmenu_filename,$fmenu_name,$fme +nu_icon)=split(/\|/,$menuitems[$ndx]); ($tid,$tmenu_type,$tmenu_show,$tmenu_filename,$tmenu_name,$tme +nu_icon)=split(/\|/,$menuitems[$tondx]); $menuitems[$ndx] = "$fid|$tmenu_type|$tmenu_show|$tmenu_file +name|$tmenu_name|$tmenu_icon\n"; $menuitems[$tondx] = "$tid|$fmenu_type|$fmenu_show|$fmenu_file +name|$fmenu_name|$fmenu_icon\n"; } open (DATABASE,">$datadir/defaults/menu.dat"); hold(DATABASE); foreach $rec (@menuitems){ print DATABASE $rec; } release(DATABASE); close (DATABASE); showmenu(); exit; }
Any help would be greatly appreciated.

In reply to 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.