V
Vijai Kalyan
Hi,
I am learning perl so was working my way through the Camel book's
first chapter. I wrote the following program to match all C-style
multiline comments.
---------------
$filename = "testinput.txt";
-e $filename or die "Invalid file. File does not exist. $!\n";
-r $filename or die "Invalid file. File is not readable. $!\n";
-f $filename or die "Invalid file. File is not a regular file. $!\n";
-T $filename or die "Invalid file. File is not a text file. $!\n";
open (FILE,"<$filename");
while ($line = <FILE>){
if($line =~ m/(\/\*[.|\n]*\*\/)/){
print "Found comment $1\n";
}
}
---------------
For RE: m/(\/\*.*?\*\/)/
I got matches for multi-line comments containing no \n. For example:
/* ... */
but not
/*
*/
I looked up "." and found that . won't match a \n. So, I modified the
RE to
m/(\/\*[.|\n]*\*\/)/
but this didn't help either. If I got it right, the above RE says"
"Match a /*. After that match as many characters as possible but match
any character or newlines followed by a */"
So, this should match
/* ... */
as well as
/*
*/
but, I find that now, nothing is matched.
Any suggestions?
thanx,
-vijai.
I am learning perl so was working my way through the Camel book's
first chapter. I wrote the following program to match all C-style
multiline comments.
---------------
$filename = "testinput.txt";
-e $filename or die "Invalid file. File does not exist. $!\n";
-r $filename or die "Invalid file. File is not readable. $!\n";
-f $filename or die "Invalid file. File is not a regular file. $!\n";
-T $filename or die "Invalid file. File is not a text file. $!\n";
open (FILE,"<$filename");
while ($line = <FILE>){
if($line =~ m/(\/\*[.|\n]*\*\/)/){
print "Found comment $1\n";
}
}
---------------
For RE: m/(\/\*.*?\*\/)/
I got matches for multi-line comments containing no \n. For example:
/* ... */
but not
/*
*/
I looked up "." and found that . won't match a \n. So, I modified the
RE to
m/(\/\*[.|\n]*\*\/)/
but this didn't help either. If I got it right, the above RE says"
"Match a /*. After that match as many characters as possible but match
any character or newlines followed by a */"
So, this should match
/* ... */
as well as
/*
*/
but, I find that now, nothing is matched.
Any suggestions?
thanx,
-vijai.