Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: How to count substrings in an array?

by sundialsvc4 (Abbot)
on Feb 04, 2013 at 15:51 UTC ( [id://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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-03-28 18:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found