in reply to Re-ordering items by $id from a flat file
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.################## 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);
The MENUITEM label is superfluous, since there's only the one loop. The if block could be recast in typical Perl postfix style as: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; } }
Next we have:last if ($fid eq $info{'m_id'});
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.$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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Re-ordering items by $id from a flat file
by Migey (Initiate) on Jun 22, 2004 at 08:28 UTC | |
by hbo (Monk) on Jun 22, 2004 at 14:29 UTC |