use Fcntl ':flock'; use Tie::File; sub reordermenu { # set $info{'m_id'), $m_action somehow # from parameters passed to this. Think # of a better data structure. my $df = tie my @menuitems, 'Tie::File', "$datadir/defaults/menu.dat"; $df->flock(O_EXCL); my @indexes = grep { $info{'m_id'} eq (split /\|/, @menuitems[$_], 2)[0] } 0 .. $#menuitems; for (@indexes) { my $tondx = $m_action eq 'moveup' ? $_ ? $_-1 : $_ : $_ == $#menuitems ? $_+1 : $_; @menuitems[$_, $tondx] = @menuitems[$tondx, $_]; } untie @menuitems; 1; }