Mario R. Sanchez, Ph.D. <> wrote:
> dear perl gurus
> 
> can someone suggest a design/approach on solving the following
> requirement: 
> 
> there is a string, say $ss, that is contained in a longer string, say
> $ls. 
> for example $ss = "jumps over" and $ls = "the cow jumps over the moon"
> 
> how do you suggest obtaining a string from $ls that is $n characters
> to the both left and right of $ss? 
> 
> for example and using the above, say $n = 4 so the results would be
> "cow jumps ove" (notice 4 characters to both the left and right of
> the target text $ss.  

Surely, that should be "cow jumps over the", i.e. including the 4
characters either side of "jumps over".

> 
> any approach would be much appreciated!

Well, its easy to find out the offset of the substring (see 'perldoc -f
index'), and you know how long the substring is (see 'perldoc -f
length'), so its just some simple arithmetic and a call to substr (see
'perldoc -f substr') to extract what you want.

HTH

-- 
Brian Raven 

-----------------------------------------------------------------------------------------------------------
This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient or have received this e-mail in error, please advise 
the sender immediately by reply e-mail and delete this message and any 
attachments without retaining a copy. Any unauthorised copying, disclosure or 
distribution of the material in this e-mail is strictly forbidden.


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to