Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re-ordering items by $id from a flat file

by hbo (Monk)
on Jun 22, 2004 at 04:31 UTC ( #368611=note: print w/ replies, xml ) Need Help??


in reply to Re-ordering items by $id from a flat file

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.


Comment on Re: Re-ordering items by $id from a flat file
Select or Download Code
Re^2: Re-ordering items by $id from a flat file
by Migey (Initiate) on Jun 22, 2004 at 08:28 UTC
    accesscheck() is a seperate sub that verifies if the user trying to access this function has the proper access level.

    Hold/release are just the new standards for lock/unlock or file_lock/unfile_lock but are not necessary for this sub.

    Cobra is a seperate .pm file for this portal that I don't fully understand yet but was also not necessary for this sub. It can array db items with the one line of code rather than going through the normal open/@/close method.
    $m_action is defined in a previous sub that shows calls all actions and operations for a selected menu being modified.
      OK, but the important question is the last one. Are we doing one swap per call? What is the context of this sub?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://368611]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2014-08-23 09:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (173 votes), past polls