in reply to weird subroutine behavior

It is truly a weird and difficult problem. Lacking any deep expertise in this area, I'm inclined to suppose that you're hitting a strange perl bug related to pad handling. Anyway...

... output of the "section 2" will contain 5 strings (I consider this the proper behavior of the subroutine "all")

Are you absolutely sure? Let me make a suggestion. I notice that you're not really using %substrings in a way suited to a hash. You add values sequentially, and then iterate over the (sorted) values. You never use the keys at all. Try replacing that hash with an array, pushing the values (those 4-tuples) onto it, and sorting that array of values. When I modified your program in this way, I got consistent behavior — but it was consistently the way other than what you said you consider the correct way.

A word spoken in Mind will reach its own level, in the objective world, by its own weight

Replies are listed 'Best First'.
Re^2: weird subroutine behavior
by flaviusm (Acolyte) on Apr 03, 2008 at 22:03 UTC

    Good news.
    I replaced the hash with an array and the results were at least consistent.
    I analyzed the output and I found a flaw in my algorithm. I fixed the algorithm and the program works fine now.
    However, the weird behavior remains, ... maybe as a meditation.

    Thanks a lot.

      Excellent! Would you mind posting your updated code?

      However, the weird behavior remains,

      I assume you mean it remains in the original code, but not in your new version, right?

        Modifications:
        - I commented out the second for loop in the subroutine since it was redundant and overlapping
        - I changed the type of "substrings" from hash to array as you suggested.
        Please see below the modified code:

        Regarding the previous version, the weird behavior remains.
Re^2: weird subroutine behavior
by flaviusm (Acolyte) on Apr 03, 2008 at 16:16 UTC
    I will do hash->array change tonight and I will let you know how it goes. Thanks.