Link to home
Start Free TrialLog in
Avatar of BrentNJ
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($place,-$total,$sum-$total[++$place]);
       if (($total += $total[$place]) > 3) {
                                          break;
                                          }
  }

}


Function in perl is
   for my $place( 1..@couples ){
       $sum += $sum[$place];
       $rank[$couple]=[$place,-$total,$sum,-$total[++$place]], last if ($total += $total[$place]) > @placements/2;
  }
Avatar of BrentNJ
BrentNJ

ASKER

Should have read $rank[$i] but same problem
SOLUTION
Avatar of AlanJDM
AlanJDM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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


ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BrentNJ

ASKER

Thanks!! I'll give it a try now.
Avatar of BrentNJ

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.
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 :-)
Avatar of BrentNJ

ASKER

This is what I did so far

for ($place=0;$place<6;$place++) {
       $sum2 += $sum[$place];
       $rank[$couple]=array($place,-array_sum($total),$sum2-$total[++$place]);
       $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.
Avatar of BrentNJ

ASKER

Will try again tonight.
Avatar of BrentNJ

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.
Avatar of BrentNJ

ASKER

Thanks for your help