我有一個非常簡單的解決方案如果#include
可以考慮塞:
use strict;
use warnings;
use English qw<$RS>;
use English qw<@LAST_MATCH_START>;
*::STDIN = *DATA{IO};
my $old_rs = $RS;
local $RS = "*/";
local $_;
while (<>) {
if (m{/[*](?:.(?!:[*]/))*\n(?sm-ix:.(?!:[*]/))*[*]/}m) {
substr($_, $LAST_MATCH_START[0]) = '';
print;
last;
}
print;
last if m/^\s*#include\b/m;
}
$RS = $old_rs;
print while <>;
__DATA__
##include<stdio.h>.
// This is a c File
// This File does sampling the frequency
/* A mline comment not multi */
/* This uses the logic ...
.....
.....
*/
#include<stdio.h>
請注意,我不得不改變最初的#include
這麼個在劇本作品。對我來說,看起來很簡單,如果我想要多行註釋,最簡單的解決方案是將'*/'
作爲我的記錄分隔符,而不是在各行上進行大量切換。
但先行,需要緩衝,並提出瞭解決混亂:
use strict;
use warnings;
use English qw<$RS>;
use English qw<@LAST_MATCH_START>;
*::STDIN = *DATA{IO};
my $old_rs = $RS;
local $RS = "*/";
local $_;
my ($rin, $rie);
my $mline = '';
my $buffer;
while (<>) {
if (m{/[*](?:.(?!:[*]/))*\n(?sm-ix:.(?!:[*]/))*[*]/}m) {
my $split = $LAST_MATCH_START[0];
print substr($_, 0, $split);
$mline = substr($_, $split);
last;
}
print;
}
$RS = $old_rs;
while (<>) {
$buffer .= $_;
if (/^\s*#include\b/) {
$mline = '';
last;
}
}
print $mline, $buffer;
print while <>;
__DATA__
#include<stdio.h>.
// This is a c File
// This File does sampling the frequency
/* A mutli-line comment not on multiple lines */
/* This uses the logic ...
.....
.....
*/
#include<stdio.h>
頭行不提問內容匹配嗎? – hfs
重要缺失信息:第一個#include不在您的原始文件中,我認爲這是編輯器錯誤?什麼規則適用於「第一評論」?任何'#include'語句之前的註釋? – TLP
你會如何判斷「它不在」的情況?看起來你總是要看看是否有'#include'來知道你是否想要刪除一個多行註釋。 *誰曾經想過放入* BEFORE *文件。 – Axeman