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

Re: [FWP] subexpr nearest the 'middle' of expr



On Thu, Mar 08, 2001 at 05:23:59PM -0800, Jacob Carpenter wrote:
> I think the return value of &replace_mid('aaa', 'a+', 'B') should be 'B',
> but that's just my humble opinion. How would one handle true expressions,
> instead of mere strings?

	Well, my sub kind of handles them. Completly by accident, mind you, but it
kind of handles them. :)

> Yanick, your sub doesn't care much for a string containing newlines, merely
> a trifle, but I thought I'd mention it.  

	Add a 's' to the right place. Should fix it.

> Also, why did you predecrement and
> +1 instead of just postdecrimenting?

	Hmm... Can I plead momentary dementia? 

Fixed code:

sub replace_mid
{my($s,$t,$r)=@_;my$l=length$s;1while$l--
&&$s!~s/(.{$l,})$t(.{$l})/$1$r$2/s;$s;}


Joy,
Yanick

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