krisahoch has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monks,
I am trying to interpolate java style property values simuliar to the way ant does it. See below
In this example, product.dir expands to be /usr/build/productbuild.dir = /usr/build product.dir = ${build.dir}/product
I am using the Config::Properties module for a base. I have a function that takes a properites hash
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).# File contents build=/usr/local/build eval=evaluation full=distribution PRODUCTONE=${build}/${eval} PRODUCTTWO=${build}/${full}/Second
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...
Please help.#===================================================================== += 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}); } #--------------------------------------------------------------------- +-
Kristofer Hoch
Si vos can lego is, vos es super erudio
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Interpolating Property strings help.
by sauoq (Abbot) on Jan 25, 2003 at 00:28 UTC | |
by krisahoch (Deacon) on Jan 25, 2003 at 04:29 UTC | |
by Aristotle (Chancellor) on Jan 25, 2003 at 12:07 UTC | |
|
Re: Interpolating Property strings help.
by Aristotle (Chancellor) on Jan 25, 2003 at 00:36 UTC |