in reply to sprintf using variables for format and variables to do a search and replace, sprintf issues
First, this /ee stuff is messy and I read this post StackOverflow re: variable in replacement side which talks about some of the details.
Then I came across: String::Substitution module.
I figured that this module does exactly what you want, so I installed and tested it.
You can read thru the docs and see more options.use strict; use warnings; use String::Substitution qw(gsub_copy); my $in_string = 'foo.ra'; my $find_exp = '\.(.)(.)$'; my $replace_exp = 'b$2$1s'; my $output = gsub_copy($in_string, $find_exp, $replace_exp); print "$output\n"; # prints: foobars
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sprintf using variables for format and variables to do a search and replace, sprintf issues
by kevins4perl (Initiate) on Mar 07, 2023 at 22:09 UTC |