How much is it going to cost me (in CPU use) to count the "\n" characters in a string?
I'm getting the string by sysread on a socket into a buffer (not necessarily empty when I start). Somebody else is consuming off the front of the buffer, writing it out another port, so I need to get the line count for the bit I've just read and add that to my running total before I exit.
I'm thinking in terms of looping, using substr, to examine each character; vs. doing something with regexps (it's obvious how to find the first \n in the range, and I can use the length of the match string to tell me where to start searching for the next); vs. using unpack or something to make an array, and grep to find the newlines, and get the count by calling it in a string context.
All of these are sounding a little like too much work to justify for adding a line count to the logging. At the very least, I should check the log level before doing the work. Anyway, I'm wondering how noticeable it'll be. I guess it's just CPU time, which we're not short of (each proxied connection gets its own child process).