in reply to Re^4: Need to replace string from external file
in thread Need to replace string from external file
I think the best approach is to split up your problem into several parts:
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
|
|---|