Quote:
Originally Posted by ownedbycats
Code:
program:
cost = $$#purchasecost;
switch_if(
cost == 'none', '',
'[Bundle]' inlist $#admintags, '[Bundle]',
'kobopoints:' inlist $#admintags, '[Kobo VIP]',
cost ==# '00.00', '$0.00',
cost <=# '00.99', '$0.01 - $0.99',
cost <=# '04.99', '$1.00 - $4.99',
cost <=# '10.00', '$5.00 - $9.99',
cost <=# '15.00', '$10.00 - $14.99',
cost <=# '15.00', '$10.00 - $14.99',
cost <=# '20.00', '$15.00 - $19.99',
cost <=# '30.00', '$20.00 - $29.99',
'$30.00 and up'
)
This returns [Bundle] for nearly everything, even when the entry doesn't exist in admintags. It doesn't happen when I remove square brackets in the test. What happened?
|
The left-hand side of inlist (the search string) is a regular expression. Square brackets are regexp character classes. You need to escape them if you want them to be normal characters. Use
Code:
'^\[Bundle\]$' inlist_field '#admintags', '[Bundle]',
The anchors ensure that the value matches the entire list item, not a substring.
Note that you can also use the str_in_list() function that doesn't use regular expressions and returns 'found_val' only if the value matches an entire list item.