2
pChainCtrl 
pChainName 
pDef 

pChainCtrl 
pArgs 

pChainCtrl
pChainCtrl 
name 
pChainTable

These are arguments of few functions,Need to add them to a function template in front of "@param[in ]"

TEMPLATE

/**
********************************************************************************
*  @fn                                                            
*  @brief
*  @param[in ]                                                         
*  @return
********************************************************************************
*/

MY CODE

use strict;
use warnings;


open(FILE3,"< functions2.txt")or die $!;
my @array1 = <FILE3>;

foreach my $arg (@array1){
    open(my $FILE4,"+< function_template.txt")or die $!;;
    seek( $FILE4, 197, 0);     // takes pointer infront of @param[in ]
    chomp $arg;
    print $FILE4 "$arg";
close($FILE4);
}
close(FILE3);

It adds arguments one by one.

I need to add the each set of arguments to file template which will be copied elsewhere(I have code for that) and then move on to next set of arguments

OUTPUT REQUIRED

/**
********************************************************************************
*  @fn                                                            
*  @brief
*  @param[in ]   pChainCtrl 
                 pChainName 
                 pDef                                                        
*  @return
********************************************************************************
*/
4

1 回答 1

1

您可以阅读模板一次并将其用于每组参数,

use strict;
use warnings;

open(my $FILE4, "<", "function_template.txt") 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;
}
于 2013-09-30T12:12:00.717 回答