Have an idea?

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

Perl Modules in Lighthouse for code re-usability

In Sawtooth we are able to include our own Perl library file which is in grpahics path by using the "require" statement after getting response from Zach. You can see the response in the below link.


But when we are using the same thing within Lighthouse studio (9.5.3), we are getting a script error while running the survey locally using "Test Survey" option whereas when the same is uploaded into hosting server and in the link we are not getting any error and server is able to compile our Perl code.

Below is the script error shown while the survey is run locally

There is an error in list building: Script:ADD("A1List"); RANDOMIZE(); require "../graphics/JRAPerl.pl"; my $li=LISTVALUESARRAY("A1Const");my $l=substr($li,1,length($li)-2);my @ar=split(",",$l); my @nums=(7,8,9); my @RowArray=JRAPerl::GroupRandN(\@nums,\@ar,0); my @nums1=(11,12); @RowArray=JRAPerl::GroupRandN(\@nums1,\@RowArray,1); REMOVE("A1List",1,15); for(my $a=0;$a<@RowArray;$a++) { ADD("A1List",$RowArray[$a]); } [ID: 132]
System Error:
Can't locate ../graphics/JRAPerl.pl in @INC (@INC contains: E:/LIVEPR~1/PROGRA~1/LIGHTH~1/PROG_T~2/TESTSU~1/cgi-bin E:/Live Projects/Programming Templates/Light House Studio Templates/Prog_Template - Copy/Test Survey/cgi-bin C:/Program Files/Sawtooth Software/Lighthouse Studio 9.5.3/perl/site/lib C:/Program Files/Sawtooth Software/Lighthouse Studio 9.5.3/perl/vendor/lib C:/Program Files/Sawtooth Software/Lighthouse Studio 9.5.3/perl/lib .) at (eval 124) line 4, line 18.

Can anyone would let us know if any other keyword or procedure would help us to execute the Perl code written in our own external Perl library file when the survey is run locally.

Thank you!
asked Apr 24, 2018 by KarthikMahankali Bronze (1,750 points)

1 Answer

+1 vote
Best answer
To save on hard drive space, Lighthouse Studio does not copy your /graphics/ folder into your /Test Survey/ folder when running Test Survey.  Because of this, the path to /graphics/ relative to the study files is different during Test Survey than with a live survey.  There are two ways you can work around this.

Option 1 is to use different paths in your Perl.  The path during Test Survey requires an additional "../".


require '../../graphics/FILE.pl';


require '../graphics/FILE.pl';

Option 2 is to open your survey files and manually copy-and-paste the /graphics/ folder into /Test Survey/.  This puts your graphics and Perl code in two places, so be careful to not make any changes to one location and not to the other - that could cause Test Survey to behave differently than the live survey.
answered Apr 24, 2018 by Zachary Platinum Sawtooth Software, Inc. (100,575 points)
selected Apr 25, 2018 by KarthikMahankali
Thank you so much Zach. I have tried both the solutions and both solved my problem.