我有一个函数名“ChainCtrlBuildChain”作为文件(FILE)中的文本。
A c file(FILE1) with content
VideoChainT* ChainCtrlBuildChain(ChainCtrlT* pChainCtrl, char* pChainName, ChainDefT* pDef)
{
...
{
ModTrace((ModT*) pChainCtrl, "ChainCtrlBuildChain: ERROR, chain init failure [chain: %4.4s inst: %d] [err: %d]\n",
...
}
我的代码:
my @Array=<FILE>;
my @Array1=<FILE1>;
foreach my $text (@Array1){
if (index($text, $Array[0]) !=-1)
{
print "$text \n";
}
}
给出这个输出:
VideoChainT* ChainCtrlBuildChain(ChainCtrlT* pChainCtrl, char* pChainName, ChainDefT* pDef)
ModTrace((ModT*) pChainCtrl, "ChainCtrlBuildChain: ERROR, chain init failure [chain: %4.4s inst: %d] [err: %d]\n",
我想改为:
VideoChainT* ChainCtrlBuildChain(ChainCtrlT* pChainCtrl, char* pChainName, ChainDefT* pDef)
我必须将其概括为输入文件由用户提供而不是修复。
我在想
if (index($text, $Array[0]) != -1 && index('**WHAT SHOULD I WRITE SO THAT IT SKIPS ANY ARGUMENTS PRESENT AND JUST CHECKS WHETHER ITS A FUNCTION DEFINITION OR NOT**')!= -1)
答案 0 :(得分:1)
如果你满足于使用你的函数名加上(
足以用于函数定义,那么这应该有效:
#!/usr/bin/perl
use warnings;
use strict;
my $function_file = 'functions.txt';
my $src_file = 'src.c';
open(my $ff,'<',$function_file) or die "Cant open $function_file: $!\n";
open(my $sf,'<',$src_file) or die "Cant open $src_file: $!\n";
my @array = <$ff>;
my @array2 = <$sf>;
close($ff);
close($sf);
foreach my $func (@array){
chomp $func;
foreach my $src_line (@array2){
if ($src_line =~ /$func\(/){
print $src_line;
}
}
}
顺便说一句:如果你使用3-arg打开,你的生活会减少痛苦!