Have an idea?

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

Perl Question

I have a  list that could contain up to 21 values.  I would like to evaluate the number of values in the list and add a value to a constructed list if the list does not contain a certain value,  add another value if the list contains two certain values.

To clarify more, if the list has the following values 3,4,5,8,9, 14,16,18,20, I would like to add a 1 if the list  does not contain the value 14.  Add a 2 if the list contains  the value 14 and if the list contain another value other than the value 14.

I tried the following code


Begin Unverified Perl

my $ i = 0;

for($i = 1; $i <= LISTLENGTH("BrandCount"); $i++)
 {
      if (LISTVALUE ("BrandCount", $i) !=14)
      {
           ADD ("MasterBrandQuotaList",1);    
      }
 }

End Unverified



This does not work because the last value is 20.   But the 6th value is a 14 so I don't want to add a 1 to the constructed list.

Please let me know how I can accomplish this.

Thank you in advance.
asked Mar 26 by Sandy

1 Answer

0 votes
Use List has parent memeber fucntion directly instead of repeating for all the elements for just adding '1' by using 1st if condition as below and for adding 2 use the 2nd if condition.
Begin Unverified Perl
if (Not(LISTHASPARENTMEMBER("BrandCount", 14)))
 {
           ADD ("MasterBrandQuotaList",1);    
 }
 if (LISTHASPARENTMEMBER("BrandCount", 14) && LISTLENGTH("BrandCount")>1)
 {
           ADD ("MasterBrandQuotaList",2);    
 }
End Unverified
answered Mar 26 by KarthikMahankali Bronze (4,475 points)
Hello,

Thank you for responding.  I am getting a Sawtooth Error #132
System Error:
Undefined subroutine &authlib9_8_1::Not called at (eval 203) line 4, line 16.
All Sawtooth Script functions must be written in ALL CAPS when used in unverified Perl.
I figured out were the error message was coming from.  I changed the code to the below and it works!  Thanks again.  This is so much better than what I originally had.

if (not(LISTHASPARENTMEMBER("BrandCount", 14))) 
 {
           ADD ("MasterBrandQuotaList",1);    
 }
...