Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Perl Error in combined IF Statements

I calculated scores using hidden values, I need now to compare them to select which has the highest and save an assigned value to another hidden segment variable (Segment_grp).
I'm getting error #132 with the code below to classify people in the first 2 segments.  

The admin module says System Error: syntax error at (eval 49) line 4, near ") {"

Don't know what that means. Can someone spot the error in this code?

<input name="Segment_grp" id="Segment_grp" type="hidden" value="
[% Begin Unverified Perl
my $seggrp=0;
if (((VALUE ("Seg1_grp") >(VALUE("Seg2_grp")) && ((VALUE ("Seg1_grp") >(VALUE("Seg3_grp")) && ((VALUE ("Seg1_grp") >(VALUE("Seg4_grp")) && ((VALUE ("Seg1_grp") >(VALUE("Seg5_grp")))

{
 $seggrp=1;
}

 elsif (((VALUE ("Seg2_grp") >(VALUE("Seg1_grp")) && ((VALUE ("Seg2_grp") >(VALUE("Seg3_grp")) && ((VALUE ("Seg2_grp") >(VALUE("Seg4_grp")) && ((VALUE ("Seg2_grp") >(VALUE("Seg5_grp")))

{
 $seggrp=2;
 
}

 return $seggrp;
 
End Unverified %] "> 
asked Oct 30, 2021 by rinsights Bronze (890 points)

1 Answer

+1 vote
To cut a long story short, your parenthesis were "out of whack". Just some tidying up of the brackets and I'm sure you will be up and running.

Replace your Perl code with this script ...
[%Begin Unverified Perl

 my $seggrp=0;

 if ((VALUE("Seg1_grp") > VALUE("Seg2_grp")) && (VALUE("Seg1_grp") > VALUE("Seg3_grp")) && (VALUE("Seg1_grp") > VALUE("Seg4_grp")) && (VALUE("Seg1_grp") > VALUE("Seg5_grp")))
  {
   $seggrp=1;
  }
 elsif ((VALUE("Seg2_grp") > VALUE("Seg1_grp")) && (VALUE("Seg2_grp") > VALUE("Seg3_grp")) && (VALUE("Seg2_grp") > VALUE("Seg4_grp")) && (VALUE("Seg2_grp") > VALUE("Seg5_grp")))
  {
   $seggrp=2;
  }
 
 return $seggrp;
  
End Unverified%]

I assume your variable names are all correct, so just a Perl script replacement should do the job.
answered Oct 31, 2021 by Paul Moon Platinum (96,920 points)
Thank you, Paul! You are a miracle worker!!!
I'll let my wife know.
I always told her I was.
...