View Single Post
Old 09-09-2024, 06:06 PM   #711
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,455
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
I'd like to replace my 'Add Cleanup tag' and 'Remove Cleanup tag' action chains with a single one that toggles it.

Code:
program:

	if 
		'[Cleanup]' inlist $tags 
	then 
		list_difference($tags,'[Cleanup]' , ',') 
	else
		list_union($tags,'[Cleanup]' , ',')
	fi
Line 8 is failing - it works on its own, so the mistake is something with the conditions. What did I do wrong?
The left side of the inlist operator is a regular expression. Brackets open a character class, so your 'if' is asking if any of the letters c, l, e, a, etc are in the tag. Use '\[Cleanup\]' to avoid the character class.

If the tag is actually the string '[Cleanup]', which your list_... expressions imply, then you can use the str_in_list() function to avoid regular expressions. Something like
Code:
program:

	if 
		str_in_list($tags, ',', '[Cleanup]', 1, '')
	then 
		list_difference($tags,'[Cleanup]' , ',') 
	else
		list_union($tags,'[Cleanup]' , ',')
	fi
This form is likely to be faster.
chaley is offline   Reply With Quote