Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: indexing in strings

by BrowserUk (Pope)
on Nov 24, 2012 at 14:38 UTC ( #1005378=note: print w/ replies, xml ) Need Help??


in reply to indexing in strings

I have 2 strings, with one being a substring of the other, like: $big_string=... & $small_string=... For the small string I have a label string: $label_for_small=... What I would like to do is to first identify the "small" substring into the "big" one, and then add, respectively, 'I's and 'O's (or the opposite) in the start and end positions.

Add Is & Os ... to what? The big string? The small string? The label string? A post-it on the back of your keyboard?

I'm thinking to use index, would this be efficient solution?

Yes. index locates strings within strings efficiently.

But your description of what you then want to do is about as clear as mud.

And how would I know how many 'O's and 'I's must I add in order for the "small" substring to grow into the length of the "big" one?

So you want to grow the small string to be the same length as the big one? If so, what is the label for?

Your label seems to contain the Is & Os you mention, but as the label is shirt than the big string, and you have mamy of each, they do not represent the start and end positions of the matched substring? And what are the Ms for?

Try asking your question again, this time imagine you are explaining it to someone with no knowledge of computers.

You might also like to give an example of (much shorter!) inputs and the required output(s).

A picture is worth a thousand words.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

RIP Neil Armstrong


Comment on Re: indexing in strings
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005378]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2014-12-23 01:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (133 votes), past polls