嵌套注释修改的问题,可以使用perl解决么?

同Page 1最后:


    open FILE, $ARGV[0] or die "Where the hell is $ARGV[0]?";
    my $str = join "", <FILE>;
    close FILE;
   
    while ($str =~ s~(/\*[^/]*)/\*~$1**~g) {};
   
    print "\n$str";

谢谢。这个脚本完全解决了我的问题。

另外,在google group上问到的一个sed脚本,但是也只能处理多行的情况
还是贴到这里吧。

[Copy to clipboard] [ - ]
CODE:
#!/bin/sh
#author by Rakesh Sharma
#e-mail [email]sharma......r@hotmail.com[/email]
#2007-09-11

sed -e '
####
### fix runaway c-comments
#

## Skip noninteresting line, i.e., one that doesnt contain a /*
\:/\*:!b

## Now we know that this line has a /*.
## Does it also contain a */ in order to make it a valid inline comment? if yes, then skip it too.
\:/\*.*\*/:b

## Now we know that this is a runaway multiline comment
## Gobble up the following lines till u see a */ in a line or u hit EOF, in which case we promptly print
## in the pattern space and quit.
:a
$q;N
\:/\*.*\*/:!ba

## perform the substitution /*    --->    ** only for second onwards /* patterns found in the pattern space
:b
s:/\*:**:2
tb
'