Have an idea?

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

Using IF AND logic in perl

I'm trying to customize the text of ACBC questions (BYO in particular) based on type of respondent, which is a passed-in variable.

Here's the "standard" uv perl from LHS help:

begin unverified perl

if(QUESTIONNAME() eq "widgit_Screener1")


return "Here are a few widgets you might like.";




return "Here are a few more widgets you might like.";


end unverified


I tried modifying "if" statement to read :
if(QUESTIONNAME() eq "widgit_Screener1 and HTYPE() ==1")

but that leads to "begin unverified perl without end unverified" error.

Any ideas?
asked Dec 22, 2019 by anonymous

1 Answer

0 votes
Below is an example of some Perl script.

Note the syntax. Perl is case sensitive so variable names must be specified as you define them. Functions must be specified as per the help reference.
[%Begin Unverified Perl

 my $Q1Script="";

 if(VALUE("QA")==1 && VALUE("QB")==1) 
   $Q1Script="The box is red."; 
 elsif(VALUE("QA")==1 && VALUE("QB")==2) 
   $Q1Script="The box is blue."; 
   $Q1Script="The box is green."; 
 return $Q1Script;
End Unverified%]

Just a couple of issues I spotted in your script ...

*Only use "eq" in your conditional script if you are referring to a text question/variable.
*Use "||" for OR and "&&" for AND.
*Nest the apostrophes correctly around variable names. Use my example as a guide.
*Use VALUE("Q1") or GETVALUE("Q1") when referring to variables.

Let me know how you go.
answered Dec 22, 2019 by Paul Moon Platinum (80,455 points)