perl regex - 提取函数定义参数

时间:2013-09-26 09:22:33

标签: regex perl

eErrorT ChainCtrlExit (ChainCtrlT * pChainCtrl)
ChanT* ChainCtrlGetBitStreamChan (ChainCtrlT * pChainCtrl, 
char * name 
)
eErrorT ChainCtrlInit (ChainCtrlT * pChainCtrl, 
char * name, 
int instance, 
void * pOwner 
)

int SymContDecNamesCount = (sizeof(SymContDecNames)/sizeof(SymContDecNames[0]))
char* SymContEncNames[]
int SymContEncNamesCount = (sizeof(SymContEncNames)/sizeof(SymContEncNames[0]))

I want to extarct only function arguments ...that is 

OUTPUT I NEED只需在一行中提取函数定义参数

 ChainCtrlT * pChainCtrl
 ChainCtrlT * pChainCtrl, char * name 
 ChainCtrlT * pChainCtrl, char * name, int instance, void * pOwner  

我的代码

open(FILE, "< functions2.txt") or die $!;
open(FILE1, "> functions3.txt") or die $!;            

my @Array1=<FILE>;
foreach my $text (@Array1){
   $text =~ /\((.+)\)/;
   print FILE1 $text;
 }

但它正在将所有内容提取到新文件中。基本上是文件内容的结合

1 个答案:

答案 0 :(得分:2)

open(my $FILE, "<", "functions2.txt") or die $!;
open(my $FILE1, ">", "functions3.txt") or die $!;            


my $s = do { local $/; <$FILE>; };
while ($s =~ /^ \S+ \s+ \S+ \s* \( (.+?) \) /xsmg) {
  my $arg = $1;
  $arg =~ tr|\r\n||d;
  print $FILE1 "$arg\n";
}