This one time, at band camp, Norman Gaywood wrote:
>On Wed, Dec 19, 2007 at 12:46:51PM +1100, Scott Ragen wrote:
>> [EMAIL PROTECTED] wrote on 19/12/2007 11:34:30 AM:
>> > Norman Gaywood wrote:
>> > > perl -00 -ne 'print tr/,//' input.txt
>> > 
>> > I nominate the perl soln as the winner so far: runs like
>> > a bat of out hell and is the most easy to understand.
>> > And the shortest in source code size.
>> 
>> I have to disagree. Whilst it may be fast, its not 100% correct.
>> Most of the time it would probably work, but if there are any blank lines, 
>> it outputs the current count, and starts again.
>> 
>> Consider the following file contents:
>> --file contents--
>> this,is,the,first,line
>> this,is,the,second
>> 
>> the,above,was,a,blank,line
>> 
>> and,another,blank,line
>> --end file contents--
>> 
>> On Jeff's original command:
>> sed 's#[^,]*##g' input.txt | tr -d '\n' | wc -m
>> 15
>> 
>> The perl command:
>> perl -00 -ne 'print tr/,//' input.txt
>> 753
>
>You are correct. I misread the perlrun man page. -00 means paragraph
>mode. I wanted slurp mode, which is the slightly uglier -0777. So the perl
>solution should be:
>
>perl -0777 -ne 'print tr/,//' input.txt
>
>There is also the slightly shorter, tending to perl ugly instead of
>perl neat:
>
>perl -0777 -pe '$_=tr/,//' input.txt

If that's more readable and reducing human cost over people cost, I quit.
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to