Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2014-10-20 10:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (75 votes), past polls