Greetings and Salutations most learned Monks,

I petition you today on a matter beyond my novice ability. What I am trying to do may not even be possible, but here goes, see bolded text for the actual question.

As a part of processing, these variables get populated early in the process

$a_test="1"; $b_test="the RTE";
Later in the process, when writing to the logfile, this line of text gets retrieved from a message table and is placed in variable $text

  $text='titl=This is test $ma_test of $mb_test broadcasting system';

Attempting to populate variables in retrieved string with those already defined and populated earlier in the process

$start=1; while (index($text,'$',$start) > 0) { $dsign=index($text,'$',$start); $blank=index($text,' ',$dsign); $w=substr($text,$dsign,($blank-$dsign)); ${(substr($w,1,length($w)-1))}=${(substr($w,2,length($w)-2))}; $start = $blank += 1; print " result: ${(substr($w,1,length($w)-1))}\n"; }
Iteration 1 prints "result: 1"
Iteration 2 prints "result: the RTE"

Values of resolved variables
  print "ma_test: $ma_test\n";
prints out ma_test: 1
  print "mb_test: $mb_test\n";
prints out mb_test: the RTE

Create and populate variable $titl with the remaining text in the string

${(substr($text,0,4))}=substr($text,5,length($text)-5); print " output: $titl\n";
looking for this: This is test 1 of the RTE broadcasting system
Instead get this: This is test $ma_test of $mb_test broadcasting system

Is it possible to resolve the variables in the text string to the values in $ma_test and $mb_test?

Thank you for any consideration

R_D


In reply to Resolving Imbedded Variables by Red_Dragon

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.