Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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]
and a log crumbles through the grate...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2018-06-25 14:26 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.