[TAG] Re: PROBLEM

Benjamin A. Okopnik editor at linuxgazette.net
Sat Nov 20 08:18:36 MSK 2004


On Fri, Nov 19, 2004 at 12:19:43PM -0700, Mike Orr wrote:
>
> If I really
> wanted to count braces, I would write a Python program.
> 
> ``
> #!/usr/bin/env python
> """count-braces.py
> 
> Usage: count-braces.py <filename
> Print the number of {}() characters in the input file.
> """
> import re, sys
> 
> braceRx = re.compile( R"[{}()]" )
> text = sys.stdin.read()
> hits = braceRx.findall(text)
> print len(hits)
> ''

Jeez. Pythoneers. Always making things more complicated. :)

perl -0wne'print y/{()}//' file.c


* Ben Okopnik * okopnik.freeshell.org * Editor-in-Chief, Linux Gazette *
-*- See the Linux Gazette in its new home: <http://linuxgazette.net> -*-




More information about the TAG mailing list