Traslation: memmove to perl

G

gamo

I am not sure about how could I translate this:

if($pos<$SIZE){
if($pos<$SIZE-1){
# memmove($min+$pos+1, $min+$pos, ($SIZE-1-$pos)*sizeof(int));
splice @min, $pos, $SIZE-1-$pos, $min[$pos+1..$SIZE-1];
}
$min[$pos] = $item;
}

or this one:

if($flag){
# my $block = ($TOTAL-1-$try)*sizeof(int);
# memmove($rest+$try, $rest+$try+1, $block);
splice @rest, $try, $TOTAL-1-$try, $rest[$try+1..$TOTAL-1];
$placed++;

search(\@board, \@rest, $placed);

$placed--;
# memmove($rest+$try+1, $rest+$try, $block);
$rest[$try] = $pick;
}

Any help is appreciated.
TIA
 
X

xhoster

gamo said:
I am not sure about how could I translate this:

if($pos<$SIZE){
if($pos<$SIZE-1){
# memmove($min+$pos+1, $min+$pos,
($SIZE-1-$pos)*sizeof(int));
splice @min, $pos,
$SIZE-1-$pos, $min[$pos+1..$SIZE-1];
}
$min[$pos] = $item;
}

I think it would be

splice @min,$pos,0,$item; # replaces middle 5 lines above

But there may be an off-by-one or boundary case in there somewhere.
Try it and see if it does what you want.

Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,973
Members
47,529
Latest member
JaclynShum

Latest Threads

Top