Have an idea?

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

Calling a perl module inside perl script within Lighthouse 9.8.0

We are planning to start programming the surveys using light house 9.8 and we have designed a sample study using the version 9.8.0 and was facing some troubles while executing our own Perl codes written in external Perl library when the survey is run locally. However we don’t face any issues after uploading the survey to hosting server and then running it.

Below is the script error shown while the survey is run locally
Error
There is an error in list building: Script:ADD("S7RowList"); RANDOMIZE(); require '../graphics/JRAPerl.pl'; my $li=LISTVALUESARRAY("S7RowConst");my $l=substr($li,1,length($li)-2);my @ar=split(",",$l); my @nums=(2,3); my @RowArray=JRAPerl::GroupRandN(\@nums,\@ar,1); REMOVE("S7RowList"); for(my $a=0;$a<@RowArray;$a++) { ADD("S7RowList",$RowArray[$a]); } REMOVE("S7RowList",7); ADD("S7RowList",7); [ID: 132]
System Error:
Can't locate ../graphics/JRAPerl.pl in @INC (@INC contains: C:/PROGRA~3/SAWTOO~1/LIGHTH~1/E/R&D/Lighthouse 9.7.0/9.8.0/Demo/9_8_0_Demo_V1/Test Survey/cgi-bin C:/ProgramData/Sawtooth Software/Lighthouse Studio/E/R&D/Lighthouse 9.7.0/9.8.0/Demo/9_8_0_Demo_V1/Test Survey/cgi-bin C:/Program Files/Sawtooth Software/Lighthouse Studio 9.8.0/perl/site/lib C:/Program Files/Sawtooth Software/Lighthouse Studio 9.8.0/perl/vendor/lib C:/Program Files/Sawtooth Software/Lighthouse Studio 9.8.0/perl/lib .) at (eval 99) line 4, line 14.


Can anyone would let us know if there is any procedure that would help us to include external Perl library when the survey is run locally.

FYI, we were able to include user defined Perl library into the survey by using Sawtooth and Lighthouse versions till 9.7.

Below is the link for the in which we have raised a similar question while moving to lighthouse from sawtooth
https://www.sawtoothsoftware.com/forum/17719/perl-modules-in-lighthouse-for-code-re-usability
asked Feb 25 by KarthikMahankali Bronze (3,705 points)
Doesn't that link address this problem?  In test mode, the graphics path is at "../../graphics/" instead of "../graphics/" like it is in live mode.

Alternatively, the Sawtooth Script function GraphicsPath will return one of these strings or the other depending on the survey's test / live status, handling this for you.
Zach,
I have tried using "../../graphics/" in test mode and it returned the same error. The reason behind it is 'the tool isn't creating Test Folder in survey's root folder. Instead it is creating the same in 'C' Drive of machine.

As you mentioned, I have also tried earlier using "GrpahichPath" function, but still the same error is returned, since TestFolder is not present in the root folder of the survey.

Do you think is there any other approach to access the user defined perl library file which is present in graphics path.
In addition to above comment, the created TestFolder in 'C' also don't contain graphics folder in it. I have tried copying graphics folder in it and was able to execute the perl code then by using the below statement.

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


But to copying the graphics folder into created test folder is becoming hectic since we are not sure where it is created is exactly and it has to be done every time we duplicate the survey folder or create a new project. Instead I was looking for a solution where using a statement we can do it.
Even with the test folder moved elsewhere on your device, the GraphicsPath function should be able to reach it.  Can you show me exactly how you called the function and what error you observed?
I have used the GrpahicsPath function as below.
require ''.GRAPHICSPATH().'JRAPerl.pl';
my $li=LISTVALUESARRAY("S7RowConst");my $l=substr($li,1,length($li)-2);my @ar=split(",",$l);
my @nums=(2,3);
my @RowArray=JRAPerl::GroupRandN(\@nums,\@ar,1);
REMOVE("S7RowList");
for(my $a=0;$a<@RowArray;$a++)
{
    ADD("S7RowList",$RowArray[$a]);
}

And below error was thrown by the system.
Error
There is an error in list building: Script:ADD("S7RowList"); RANDOMIZE(); require ''.GRAPHICSPATH().'JRAPerl.pl'; my $li=LISTVALUESARRAY("S7RowConst");my $l=substr($li,1,length($li)-2);my @ar=split(",",$l); my @nums=(2,3); my @RowArray=JRAPerl::GroupRandN(\@nums,\@ar,1); REMOVE("S7RowList"); for(my $a=0;$a<@RowArray;$a++) { ADD("S7RowList",$RowArray[$a]); } REMOVE("S7RowList",7); ADD("S7RowList",7); [ID: 132]

System Error:
Can't locate ../../graphics/JRAPerl.pl in @INC (@INC contains: C:/PROGRA~3/SAWTOO~1/LIGHTH~1/E/R&D/Lighthouse/9.8.0/Demo - 26-02-2020/9_8_0_Demo_V1/Test Survey/cgi-bin C:/ProgramData/Sawtooth Software/Lighthouse Studio/E/R&D/Lighthouse/9.8.0/Demo - 26-02-2020/9_8_0_Demo_V1/Test Survey/cgi-bin C:/Program Files/Sawtooth Software/Lighthouse Studio 9.8.0/perl/site/lib C:/Program Files/Sawtooth Software/Lighthouse Studio 9.8.0/perl/vendor/lib C:/Program Files/Sawtooth Software/Lighthouse Studio 9.8.0/perl/lib .) at (eval 94) line 4, line 14.
Interesting.  We must have changed something in that area.  I'm going to bring this up to a coworker to see if we can't improve this, but one workaround in the meantime might be to modify your Perl script to attempt to load in both the normal live location and the abnormal test location:

[% Begin Unverified Perl
eval {
    require '../graphics/JRAPerl.pl';
};
eval {
    require 'C:\Users\...\graphics\myperl.pl';
};
...
End Unverified %]
Thank you for forwarding to your coworker.

Can you please explain what the path "require 'C:\Users\...\graphics\myperl.pl';" exactly refers to, i.e. should I place the location to my survey folder or the location would be automatically accessed.
It would need to be the path of your survey folder.
thank you Zach.

Your solution to the original question

Please only use this to answer the original question. Otherwise please use comments.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

To avoid this verification in future, please log in or register.
...