On Tue, May 24, 2016 at 8:50 PM, Craig Pelkie <craig@xxxxxxxxxx> wrote:
I would go for a "middle-ground" approach and wrapper the unconventional usage of %xlate in a subprocedure, hopefully in a "utilities" module where other similar helper procedures are coded.
I appreciate the sentiment behind this suggestion (I get warm fuzzies
when people can find middle ground, especially in today's seemingly
ever-more-polarized world). But I think once you have committed to
"hiding" complexity in an external function, then the conciseness of
the "trick" loses its value, and you might as well just implement it
(externally) the more verbose but more straightforward way anyway.
One thing with tricks is that they tend to be either brittle or
limited. Even putting aside whether the discussed use of %XLATE is
perverted or not, it's actually limited by the fact that you need a
different character for each placeholder, instead of just one
character for all the placeholders. For example, what if your edit
mask needs 40 slots? What if it needs 300 slots?
And how is the edit mask supposed to be expressed by the caller? Jon
wanted something simple. It's much better if you can pass
'(...) ...-....'
rather than
'(ABC) DEF-GHIJ'
All the more so if your mask looks like
'A(...)-B(...)'
where 'A' and 'B' are literals (part of the boilerplate of the mask),
and thus cannot be in %XLATE's first parameter.
If you want to accept "user-friendly" edit masks, then your external
function has to have some way to translate the received parameters
into the special form required by the %XLATE trick.
For example, if you would like the interface to your function (which
I'm calling "edit" here) to be
edit('(...) ...-....', '8005551212', '.')
then your function has to be able to turn the above into
%xlate('ABCDEFGHIJ', '8005551212', '(ABC) DEF-GHIJ')
Also, it has to be able to turn
edit('A(***)-B(***)', 'FOOBAR', '*')
into
%xlate('CDEFGH', 'FOOBAR', 'A(CDE)-B(FGH)')
You will soon discover that the logic required to translate the
parameters into a form usable by %XLATE is pretty much equivalent to
using Steve's approach in the first place.
John Y.
As an Amazon Associate we earn from qualifying purchases.