$tasks->{t1}{cmdline} = "convert -f %FONT% %1%";
$tasks->{t1}{report} = "Launched as %CMD% by %USER%";
$tid = 't1';
foreach my $parm (keys %{$tasks->{$tid}}) {
$tasks->{$tid}{$parm}=~s/%FONT%/$tasks->{$tid}{font}/g; # may evaluate if $parm == 'cmdline';
$tasks->{$tid}{$parm}=~s/%CMD%/$tasks->{$tid}{cmdline}/g;
}
The code is bad, because it needs another loop outside foreach (to ensure that all copied values were replaced), and also contains too much textual data. The best way to rewrite currently looks as:
foreach my $parm (keys %{$tasks->{$tid}}) {
&lookupValues(\$tasks->{$tid}{&parm}); # or ($parm) if strict refs?
}
However it still needs to have keys sorted in order to detect priority (if %CMD% is replaced before %FONT%, $tasks->{$tid}{report} is wrong).
foreach my $parm ( &SORTME($tasks->{$tid}) ) {&lookupValuesFor($tid,$parm); }
What is a best way to sort depending on the number of specified variables and their relations? Native one (lots of loops and hashes), or expat [ Related questions are somehow pointing me to expat, would investigate it too: http://stackoverflow.com/questions/330334/parsing-a-string-for-nested-patterns/330433#330433 ] or other parser?
OOP way of $object->value('cmdline') is not liked now.