-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Je Mardo 05 Junio 2001 12:01, vi skribis:
> Here is my 5 minute attempt to create a program that extracts all
> comments in a C source file containing the string "TODO":
...
> It works fine, but I really would like to have access to the line number
> where the scan matches. Is that easy to accomplish or do I have to
> rethink the structure of the program from scratch?

Hi!

I suppose it depends on how you want the line numbers presented.  Here's 
something that works:

string = ""
IO.foreach(ARGV[0]) { |l| string += "#$. #{l}" }
todo_comments = string.scan(/\d+ \/\*.*?\*\//m).delete_if { |c| c !~ /TODO/ }

The only change (from your code) is the preformatting of the source file to 
include line numbers, and a small modification to the regex to accomodate 
them.  Run on your supplied test data, printing todo_comments produces:

7 /*
8  * TODO  foo bar
9  * flopp flerp plopp plerp blipp
10  * blopp boo.com
11  */

=== SER   Deutsch|Esperanto|Francaise|Linux|Java|Ruby|Aikido|Dirigibles|GPG
=== http://www.germane-software.com/~ser  jabber.com:ser  ICQ:83578737
"It isn't pre-marital sex if you don't get married"  -- anon
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.2 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE7HlMZP0KxygnleI8RAjzxAJ4y3oqhwVrrdX6be+ikSpOkXvFBKgCgkUoQ
VL4rP8WD94Dlx8EN8PEyDQ0=
=T+VJ
-----END PGP SIGNATURE-----