perl - need to add set of lines into a file
这是我原来的问题。
我现在的问题略有不同。我试了很久但无法修复它。
pChainCtrl
pChainName
pDef
pChainCtrl
pArgs
pChainCtrl
pChainCtrl
name
pChainTable
这些是几个函数的参数,需要将它们添加到“@ param [in]”前面的.c文件中的函数模板
.C文件的一部分
/**
********************************************************************************
* @fn ChainCtrlSetJpgSnapshotFile
* @brief
* @param[in ] //arguments needs to be added here
* @return
********************************************************************************
*/
eErrorT ChainCtrlSetJpgSnapshotFile(ChainCtrlT* pChainCtrl, RouteListItemT* pRoute, char * dst_chain, char *jpg_file_path)
{
............
}
/**
********************************************************************************
* @fn ChainCtrlSetBgFile
* @brief
* @param[in ] //arguments needs to be added here
* @return
********************************************************************************
*/
eErrorT ChainCtrlSetBgFile(ChainCtrlT* pChainCtrl, RouteListItemT* pRoute, char * dst_chain, char *bg_file_path)
{
....
}
/**
********************************************************************************
* @fn ChainCtrlSetColorBar
* @brief
* @param[in ] //arguments needs to be added here
* @return
********************************************************************************
*/
eErrorT ChainCtrlSetColorBar(ChainCtrlT* pChainCtrl, RouteListItemT* pRoute, char * dst_chain,Boolean bOnOff)
{
..........
}
我尝试了用户@mpapec
共享的代码但它仅在第一个函数中添加参数。
use strict;
use warnings;
open(my $FILE4, "<", "chaincontroller.c") or die $!;
my $tl = do { local $/; <$FILE4> };
$tl =~ s|\s+$||mg;
open (my $FILE3, "<", "functions2.txt") or die $!;
my @array1 = map [ split ],
do { local $/ = ""; <$FILE3> };
for my $arg (@array1) {
my $s = $tl;
$s =~ s|(param.+)|"$1 ". join "\n ", @$arg |e;
print $s;
}
答案 0 :(得分:1)
尝试用,
替换for
循环
$tl =~ s{(\@param.+)}{
"$1 ". join "\n ", @{ shift @array1 };
}ge;
print $tl;