BrentNJ
asked on
Fatal error: Unsupported operand types
I'm trying to convert a Perl function to PHP, I get a Fatal error: Unsupported operand types on line that starts with $rank.
I think that is because $total is actually an array but not sure. I could use some help. I asked a question on how to convert entire function. But I thought a more concise question may be easier to get help on.
Thanks!!
for ($i=0;$i<6;$i++) {
for ($judge = 0; $judge < 5; $judge++) {
$place=$placements[$judge] [$i];
$total[$place]++;
$sum[$place] += $place;
}
for ($place=0;$place<6;$place+ +) {
$sum += $sum[$place];
$rank[$couple]=array($plac e,-$total, $sum-$tota l[++$place ]);
if (($total += $total[$place]) > 3) {
break;
}
}
}
Function in perl is
for my $place( 1..@couples ){
$sum += $sum[$place];
$rank[$couple]=[$place,-$t otal,$sum, -$total[++ $place]], last if ($total += $total[$place]) > @placements/2;
}
I think that is because $total is actually an array but not sure. I could use some help. I asked a question on how to convert entire function. But I thought a more concise question may be easier to get help on.
Thanks!!
for ($i=0;$i<6;$i++) {
for ($judge = 0; $judge < 5; $judge++) {
$place=$placements[$judge]
$total[$place]++;
$sum[$place] += $place;
}
for ($place=0;$place<6;$place+
$sum += $sum[$place];
$rank[$couple]=array($plac
if (($total += $total[$place]) > 3) {
break;
}
}
}
Function in perl is
for my $place( 1..@couples ){
$sum += $sum[$place];
$rank[$couple]=[$place,-$t
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
typo...
array(inde1 => value1, index1 => value2)
should be...
array(inde1 => value1, index2 => value2)
Sorry. Thats like the 5th typo Ive made today... I think it is time to take a break.
Alan
array(inde1 => value1, index1 => value2)
should be...
array(inde1 => value1, index2 => value2)
Sorry. Thats like the 5th typo Ive made today... I think it is time to take a break.
Alan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!! I'll give it a try now.
ASKER
I actually had the sum2 in one of my tries - same problem.
Is it OK to reference the array $total as just -$total?
Maybe perl treats $total differently.
Is it OK to reference the array $total as just -$total?
Maybe perl treats $total differently.
BrentNJ,
oops, didn't notice it. no, you cannot reference array this way.
If you want to get sum of all $total elements you should use array_sum($total), in example
$rank[$i] = array($place, -array_sum($total), $sum2 - $total[$place+1]);
I'm sorry if this is not what you want, I just don't understand what your script does with these numbers :-)
oops, didn't notice it. no, you cannot reference array this way.
If you want to get sum of all $total elements you should use array_sum($total), in example
$rank[$i] = array($place, -array_sum($total), $sum2 - $total[$place+1]);
I'm sorry if this is not what you want, I just don't understand what your script does with these numbers :-)
ASKER
This is what I did so far
for ($place=0;$place<6;$place+ +) {
$sum2 += $sum[$place];
$rank[$couple]=array($plac e,-array_s um($total) ,$sum2-$to tal[++$pla ce]);
$total2 += $total[$place];
if ( $total2 > 3) {
break;
}
}
I'm not sure if the $total reference in perl is total of array contents or total in array. I'll check it out.
for ($place=0;$place<6;$place+
$sum2 += $sum[$place];
$rank[$couple]=array($plac
$total2 += $total[$place];
if ( $total2 > 3) {
break;
}
}
I'm not sure if the $total reference in perl is total of array contents or total in array. I'll check it out.
ASKER
Will try again tonight.
ASKER
I'm stuck again. The function I am trying to convert was originally asked in
https://www.experts-exchange.com/questions/21366761/Algorithm-for-Relative-Placement-Scoring.html
My perl is not as good as I thought. I don't understand all the code.
Can anyone convert to php function? Raising points.
https://www.experts-exchange.com/questions/21366761/Algorithm-for-Relative-Placement-Scoring.html
My perl is not as good as I thought. I don't understand all the code.
Can anyone convert to php function? Raising points.
ASKER
Thanks for your help
ASKER