Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: How to count substrings in an array?

by sundialsvc4 (Abbot)
on Feb 04, 2013 at 15:51 UTC ( #1016964=note: print w/replies, xml ) Need Help??

in reply to How to count substrings in an array?

Well, “goatse” is Cute Golf, but I would veto its use in a code review because it simply isn’t instantaneously obvious, not only that the code does work correctly, but that it does so in every case.

The ideal, of course, would be that the code is supported by Test::More test suites that thoroughly exercise all relevant cases to prove not only that it works properly in every case that might be thrown at it, but that it also rejects any invalid string that violates one of its design assumptions.   (That’s a lot more work for the programmer, so I usually encounter “nasty bugs in production” instead.   So do you.   So it goes.)

What if the substring contains instances of itself, or tails with its own head?
For instance, how many occurrences of aba do you want to say occurs in the string abababa?   Two, or three?   You have two design choices here, and you must know what is the right answer for the purposes of this application in a production setting.

  • Comment on Re: How to count substrings in an array?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1016964]
[Discipulus]: i published my first Dancer2 application!

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2018-01-17 11:31 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (198 votes). Check out past polls.