Phoenix.pm: Parsing comments

Thomas Whitney whitneyt at agcs.com
Tue Nov 27 18:37:05 CST 2001


Hi Group,

I am helping somebody write a simple comment parser. "{}" comments can be inside "/**/" comments, and there could be an empty comment.
Below is an attempt at it. It appears to works except the |ed expressions return empty.
I could probably do it with a few lines, but does anybody have any ideas for a better one liner?

$_ = "/*co{mm}ent*/";
my @save =  m/(?:\/\*(.*?)\*\/ |
                            \{(.*?)\}     |
                            \(\*(.*?)\*\))/xsg;
print map {"[$_]\n"} @save;

produces the following

whitneyt at tuvok[99]: junk.pl
[co{mm}ent]
[]
[]
whitneyt at tuvok[100]:


Thanks
Tom








More information about the Phoenix-pm mailing list