First, a brief house-keeping note. I edited my last post, because I had a conversation with one of our users and I realized I had not made something clear: the arrays (which I called “lists”) that are passed to REDUCE are not at all the same thing as a ShoppingAdvisor Lookup List. You can’t use a Lookup List as one of the inputs to REDUCE at all.

I always strive to be as clear as I can with these posts. Clear writing about technical subjects is tricky, though. However, the good news is that this conversation I had was the genesis of a new function that is coming with the next release. I hate to keep writing these teaser posts, but I guess it’s better than only writing a post after every release, isn’t it? Here’s the full story…

From the shores of Ev’rett Jordan
Wrote our dear friend L. in Durham:
“To my friend the good Feed Doctor,
When I read your latest missive,
Tho’ it ran to many pages,
Still I thought with great excitement
I had finally found the answer
To a problem sorely vexing.
But at last when I completed
Reading every jot and tittle
Poring over every figure
Each and every coding sample
Still I had no good solution
To the problem I am having;
Thus I’m writing you this letter.

See, quite frequently it happens
As I’m editing my templates
That I need to change the titles
Of the items I am sending
In my data feeds each morning
And the changes are as follows:
First we have a ton of phrases,
And each phrase has a replacement,
And I want to search my titles
For each phrase and then replace it.
Thus I have, exempli gratia,
The phrase “Great Big Wall Poster”
And in each and every title
Should this phrase become deleted
And in its stead the system
Should insert the words “Art Deco.”
(Yes I know this sounds quite silly
But it’s only an example.)

Now before you redirect me
To a blog post you have written
Illustrating text replacement,
Let me further up the ante:
When I said a “ton” of phrases
I really was not kidding;
Let’s just say the list is longer
Than the average blog posting
Of your neighborhood Feed Doctor.

Now I’ve mastered rules of business,
Expressions regular, unleaded,
And I know of one solution:
To encompass all my phrases
In a mess of nested function
Calls to REPLACE with my data,
Yet it still is rather daunting,
What with errors parenthetic
All but guaranteed to happen.
Furthermore it would be better
If I had some way to manage
All the phrases and replacements
In a square and ordered fashion:
In a Lookup List, most likely,
With a new and improved function
To perform the full replacement
On a text string that I pass it.”

I saw that this presented
To the vigilant programmer
A moment opportune in which
To add stakeholder value.
Starting with a testing fixture
And a set of input data
With its corresponding output
Gathered from a user story,
Proceeding with great caution
Lest the build should become broken,
A new function was created.
When at last the tests were passing,
And the bars from red were changing
To a green that’s oh so verdant
As your favorite allusion
Elegiac or pastoral,
Then the changes were committed
To the code repository
And the next build (incremental)
Picked it up and then compiled it.

Now the new replacement function
Is out on our QA servers
Waiting for a round of testing
Which will prove that it is working,
And if no-one finds a problem,
If no hidden bug is lurking
In the code that I have written
To help solve our dear L’s problem
Then when next we have a release
Of new features and bug fixes
L. then can create a new rule
That will fix up all his titles,
And in Phase 3 achieve profit.