4 ms·
But your assertion was that this was an easy problem solved with just a few lines of shell code. That assertion is only true in an extremely limited context whe
by bjourne 14y ago
But your assertion was that this was an easy problem solved with just a few lines of shell code. That assertion is only true in an extremely limited context where the only language possible is English and the only character encoding is ascii. That's where the Unix tools shines because they are great at handling problems easily expressable as regular expressions. But it is not a very realistic example, nor a fair comparison.
> As bryanlarsen pointed out, the shell solution can easily be extended by using an internationalized version of tr.
You should try that and then blog about it. :) I've spent lots of time battling issues with ascii-centric libraries. My conclusion is that it is not easy at all which is not strange because tools like tr and sed were written decades before unicode support became a must have. I can't say that it is impossible to write a shell script to count words in a text written in Arabic script, but it doesn't seem easy.
- pdonis 14y ago> But your assertion was that this was an easy problem solved with just a few lines of shell code. Where did I assert that? > I can't say that it is impossible to write a shell script to count words in a text written in Arabic script, but it doesn't seem easy. Is there a definition of what counts as a "letter" in Arabic script? That is, which Unicode code points correspond to letters? And does Arabic share the convention that a "word" is a sequence of letters delimited by non-letters? If the answers to those questions are "yes", then the extension of the algorithm already presented to handle Arabic is straightforward; it's just a matter of substituting the Arabic definition of "letters" for the ASCII definition. (With, as I said in my previous comment, the additional issue of determining the encoding of the input and output.) If some of the answers to the above questions are "no", then you have an issue with the problem specification, not with the algorithm you're going to use to solve it.