Fellow Monks,
I am trying to interpolate java style property values simuliar to the way ant does it. See below
build.dir = /usr/build
product.dir = ${build.dir}/product
In this example, product.dir expands to be
/usr/build/product
I am using the Config::Properties module for a base. I have a function that takes a properites hash
# File contents
build=/usr/local/build
eval=evaluation
full=distribution
PRODUCTONE=${build}/${eval}
PRODUCTTWO=${build}/${full}/Second
I have it resolving the first value in a variable (PRODUCTONE) to /usr/local/build. The problem is that when the second value is resolved to blank. Here is a Dumper dump (faux).
VAR '1' =
{
'build' => '/usr/local/build',
'eval' => 'evaluation',
'full' => 'distribution',
'PRODUCTONE' => '/usr/local/build/',
'PRODUCTTWO' => '/usr/local/build//Second',
}
This problem has me pulling out my hair, and I really need help. Here is the snippet of code that I am using...
#=====================================================================
+=
sub interpolateValues($)
{
my $self = shift;
return unless defined($INTWeb::Properties::INTERPOLATE_VALUES);
my $List = shift;
foreach my $listKey (keys(%{$List}))
{
my $listValue = $List->{$listKey};
#print "|--+ $listKey: $listValue\n";
if ($listValue =~ m/\$\{(.*?)\}/)
{
my $extractedVariable = $1;
my $defined = $self->isDefined($List, $extractedVariable);
$defined += $self->isDefined($self->{Resolved}, $extractedVar
+iable);
die("FATAL: $extractedVariable is not a valid propery variabl
+e name\n") if($defined == 0);
my $substituteThis = $extractedVariable;
my $substituteWith = $self->{Resolved}->{$extractedVariable};
my $final = $List->{$listKey};
$final =~ s/(\$\{$extractedVariable\}/$substituteWith/;
print "FINAL: $final\n";
}
else
{
$self->{Resolved}->{$listKey} = $List->{$listKey};
delete ($List->{$listKey});
}
}
}
sub isDefined
{
my $self = shift;
my $hash = shift;
my $key = shift;
return defined($hash->{$key});
}
#---------------------------------------------------------------------
+-
Please help.
Kristofer Hoch
Si vos can lego is, vos es super erudio