View Single Post
Old 05-10-2022, 04:37 AM   #398
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: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Question:

Code:
program:
	ids = $identifiers;
	mobi = select(ids, 'mobi-asin');
	amazon = select(ids, 'amazon');

	if 
		mobi && !amazon
	then 
		n = re(mobi, '(.*)', '\1');
		ids = list_union(ids, strcat('amazon:', n), ',')
	else
		ids
	fi;


	if 
		mobi == amazon
	then
		ids = list_difference(ids, strcat('mobi-asin:', mobi), ',')
	else
		ids
	fi
I have two books. Book #1 has only the mobi-asin identifier, while Book #2 has identical mobi-asin and amazon ids.

The results are this:

Attachment 193744

Aside from either separating the two parts into separate templates or running it twice, is there any way to tell it "do part A (copy mobi-asin to amazon), and then also do part B (remove mobi-asin)"?

EDIT: See my post in the while loop thread.
I don't understand the question. As you have it, both clauses will be executed. What do you want that is different from that?

Aside: what is the "n = re(mobi, '(.*)', '\1');" for? That (almost) copies mobo to n. Except there will be problems with the .*, which can copy the empty string. Why not just use 'mobi' in the list_union()?
chaley is offline   Reply With Quote