CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Extracting comments from C code.

 



paralacsa
New User

Dec 3, 2008, 3:24 PM

Post #1 of 2 (2252 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:

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:

Code
while (m/(\/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*+\/)/gm) { 
print("$1\n");



winfinit
User

Dec 10, 2008, 5:51 AM

Post #2 of 2 (2188 views)
Re: [paralacsa] Extracting comments from C code. [In reply to] Can't Post

are you trying to push all of the comments into an array?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives