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


In reply to Interpolating Property strings help. by krisahoch

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.