I think the best approach is to split up your problem into several parts:
- Reading input files - you already have this using Path::Tiny
- Correlating the input data and replacing the input data in the template - this part maybe needs some more clarification but basically also works
- Writing the resulting output - again, Path::Tiny offers a way to write the files
Regarding issue 2, the input data: You haven't been explicitly clear about this, but I think from your statements that the first line of the users file corresponds to the first line of the IP addresses file. If that is the case, using a templating engine is even more advised, like HTML::Template, but you can also do with the simplest templating engine, s///e:
sub fill_template {
my( $template, %values ) = @_;
my $re_values = join "|", map { "\b$_\b" } reverse sort keys %valu
+es;
$template =~ s!($re_values)!exists $values{ $1 } ? $values{ $1 } :
+ $1!gre;
}
for my $linenumber (0..$#arr) {
my $user_data = fill_template( $data, USER_C => $arr[$i], IP => $a
+rr1[$i] );
print $user_data; # well, output to a file, but that's another pro
+blem
}
Update: s/Path::Class/Path::Tiny, spotted by marto |