View Single Post
Old 04-10-2025, 05:56 AM   #829
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,482
Karma: 8025704
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
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.
chaley is offline   Reply With Quote