[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[FWP] subexpr nearest the 'middle' of expr



Let's see a subroutine that takes three (3) arguments [expr, subexpr,
replacement] -- call them whatever you like in the actual sub -- and returns
"expr" with the "subexpr" nearest the middle (currently, I intend 'middle'
to mean the byte position closest to half-the-byte-length of the string)
replaced with "replacement". Subexpr should be a literal string. and should
be centered on the middle, not begin in the middle -- i.e.
&replace_mid('aaaaa', 'aaa', 'BBB') is to return 'aBBBa' not 'aaBBB'.

In the case that the same subexpr is found 'just-left-of-center' and
'just-right-of-center,' you have discretion in which your sub favors -- i.e.
&replace_mid('aaaa', 'a', 'B') may return either 'aBaa' or 'aaBa'. I'd like
to see some for each way.

I'm certain this will clearly illustrate that TMTOWTDI, and I'm looking
forward to that. Ultimately, I have a feeling that this will result in a
golf match, but initially, I'm just interested in seeing interesting ways of
doing this.

Enjoy,
Jacob.

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe