Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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.

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
    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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://368611]
[1nickt]: That's cool Disci+

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2018-01-24 03:02 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (255 votes). Check out past polls.