Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Finding repeat sequences.

by choroba (Chancellor)
on Jun 18, 2013 at 19:10 UTC ( #1039633=note: print w/replies, xml ) Need Help??

in reply to Finding repeat sequences.

"abcdabcdabceabcdabcdabceab" =~ /(.+).*\1/

Can you give more input samples to exemplify the other constraints?

لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Finding repeat sequences.
by BrowserUk (Pope) on Jun 18, 2013 at 19:59 UTC

    They are kind of hard to come up with, but okay.

    Given the rep 'aaaabaaaaba' and a string containing one whole and one partial rep 'aaaabaaaabaaaaabaaaab'

    $s = 'aaaabaaaabaaaaabaaaab';; $s =~ m[(.+).*\1] and print $1;; aaaabaaaab

    Which isn't correct because:

    aaaabaaaabaaaaabaaaab aaaabaaaab aaaabaaaab 1 ^2

    You can fix that by removing the redundant .* per LanX's version: m[(.+)\1] but then you get:

    $s = 'aaaabaaaabaaaaabaaaab';; $s =~ m[(.+)\1] and print $1;; aaaab

    Which isn't right:

    aaaabaaaabaaaaabaaaab aaaabaaaab aaaabaaaab 1 2 ^3 4

    I realise that this is a 'cheat' as there in no complete repetition to find, but it is one possible scenario.

    Given the string will always consist of 1 or more repetitions of the substring, whatever partial substring (if any) is at the end of the string should match the same number of characters at the start of the string. That's the bit I'm having trouble wrapping my head around.

    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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1039633]
[choroba]: but undef %hash and %hash = () both work, too, but the first one keeps the memory allocated, while the latter makes it available for other parts of the program.
[choroba]: iirc
[perldigious]: karlgoethebier: Well it is a pretty old and complicated (for me) bit of code I wrote (poorly by my current standards), so I'm expecting everything to break when I add the scoping and find out what else is undesireably scope changed. :-)
[perldigious]: Ah, thanks choroba, that sort of thing was precisely what I was wondering when I asked.
[perldigious]: I didn't want to tie up memory unecessarily basically, I wanted to "delete" it specifically to free it up, and wasn't sure I was even accomplishing that.

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2017-07-21 19:53 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (335 votes). Check out past polls.