
paralacsa
New User
Dec 3, 2008, 3:24 PM
Post #1 of 2
(1430 views)
|
|
Extracting comments from C code.
|
Can't Post
|
|
Hi, first of all I know that there's such a topic in FAQ, I've read it but I didn't get answers my questions. Here is my short code:
use warnings; open(F1,"C.txt")|| die "Couldn't open file"; $/ = undef; $_=<F1>; @matches = m/(\/\*([^\*]|[\r\n]|(\*+([^\*\/]|[\r\n])))*\*+\/)/gm; print ("@matches\n\n\n"); I have multi-lined string with C code stored in $_, I'd like to get all comments from this string but when I compile file compiler is throwing such a warnings even though the output is right: Use of uninitialized value $matches[6] in join or string at kom.pl line 17, <F1> chunk 1. Use of uninitialized value $matches[7] in join or string at kom.pl line 17, <F1> chunk 1. Use of uninitialized value $matches[10] in join or string at kom.pl line 17, <F1 > chunk 1. Use of uninitialized value $matches[11] in join or string at kom.pl line 17, <F1 > chunk 1. This making me nervous. Where's the problem. This approach of getting all matches from regexp was presented in some Perl book. Approach like this is fine and works properly on the same input data:
while (m/(\/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*+\/)/gm) { print("$1\n");
|