Posted on 2006-11-20 21:42:37-08 by christopher
recurse on load?
I would love to get loading of properties files to "recurse".

For example, a properties file:
------------------------------------
dist.jdbc.hostname=10.87.8.206 dist.jdbc.sid=q60w10t3 dist.jdbc.url=jdbc:oracle:thin:@${dist.jdbc.hostname}:1521:${dist.jdbc.sid}

and this perl code to print that last property:
------------------------------------
$value = $properties->getProperty( "dist.jdbc.url" ); print "dist.jdbc.url=$value\n";

produces this output:
------------------------------------
dist.jdbc.url=jdbc:ws-oracle:thin:@${dist.jdbc.hostname}:1521:${dist.jdbc.sid}

Is there a way to get the definitions within the definitions evaluated? Thanks.
Direct Responses: 3591 | Write a response
Posted on 2006-11-21 10:17:44-08 by salva in response to 3586
Re: recurse on load?
yes, you can use a validator (an undocumented feature of Config::Properties, look in the module source for more info) to change properties as they are read:
sub my_validator { $_[2] =~ s/\$\{([\w\.]+)\}/$_[0]->getProperty($1)/ge } my $cfg = Config::Properties->new(...); $cfg->setValidator(\&my_validator); $cfg->read();
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.