I want to create similar functions with its name obtained from a list from a file. Also its content will also use the name from the list.

example: list is written in file (fun_list.txt) as:


and my function template is defined in (fun_template.txt)

uint32 enable_###(boolean val)
   ### =  val;

expected result in one single output file as (fun_clock.c):

uint32 enable_CLK_A_0(boolean val)
   CLK_A_0 =  val;
uint32 enable_CLK_A_1(boolean val)
   CLK_A_1 =  val;
uint32 enable_CLK_B_0(boolean val)
   CLK_B_0 =  val;
uint32 enable_CLK_B_1(boolean val)
   CLK_B_1 =  val;
uint32 enable_CLK_B_2(boolean val)
   CLK_B_2 =  val;

How do I achieve this in notepad++. I assume using macros we should be able to do this.

I don't have any restrictions for file names (or to be in separate files), I want to create these functions easily rather than copying it manually.

If not in notepad++, if there is some easy solution in windows (cmd) or linux that too would be good.


This small perl script does the job:

use strict;
use warnings;

# define and open the three files
my $file_lst = 'fun_list.txt';         # give the full path if doesn't run in the same dir
my $file_tpl = 'fun_template.txt';
my $file_out = 'fun_clock.c';

open my $fh_l, '<', $file_lst or die "Unable to open '$file_lst': $!";
open my $fh_t, '<', $file_tpl or die "Unable to open '$file_tpl': $!";
open my $fh_o, '>', $file_out or die "Unable to open '$file_out': $!";

# read template file in "slurp" mode
my $tpl;
    local $/ = undef;
    $tpl =  <$fh_t>;
# read the list file and replace all ### in the template with the line in  list file
while(<$fh_l>) {
    (my $tmp = $tpl) =~ s/###/$_/g;
    print $fh_o $tmp;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.