PERL: Replace multiple objects within a string

looking to replace parameters within a string with an external answer - with multiple replacements within a string %% will be used to wrap the objects to be replaced

i.e. hello %%title%% %%user%% from %%address%% you last %%action%% on %%object%%

the params will be used to make calls to a database to get the answers thenI need to substitute the answers back in.

I think I need to do this in two passed

first extract all the params and process them
then replace each param with it's results

my questions

  • how do I get the params out to an array
  • how do I substitute them back in
$
$ echo "hello %%title%% %%user%% from %%address%% you last %%action%% on %%object%%" |
> perl -ne '@x=split /%%/;
>           ($x[1],$x[3],$x[5],$x[7],$x[9])=("TITLE","USER","ADDRESS","ACTION","OBJECT");
>           print "@x"'
hello  TITLE   USER  from  ADDRESS  you last  ACTION  on  OBJECT
$

tyler_durden