in reply to printing a string from an sql field that contains a variable

You need a template engine , like Template or String::Interpolate::RE or ...
  • Comment on Re: printing a string from an sql field that contains a variable

Replies are listed 'Best First'.
Re^2: printing a string from an sql field that contains a variable
by Anonymous Monk on Jun 28, 2011 at 12:55 UTC

    Thanks.

    String::Interpolate::RE looks like the most simple of those options. I have installed it, but it isn't working as I would expect, which is along the lines of:

    Basically, with this module installed and available for my scripts to call upon the "strinterp" function mentioned on the cpan page:

    $str = strinterp( $template );

    Where $template is the string I pulled from my database and $str becomes the new string with the variables ($me, $friend, etc) replaced by their current values in the script.

    If so... great, that would be a tidy solution.

    Unfortunately, this just gives the error:

    "Undefined subroutine &main::strinterp called at C:\Users\rest of path\"

    What should I do next? (Thanks in advance, any help is appreciated).

      Do you have this line at the start of your code?

      use String::Interpolate::RE qw( strinterp );
      ~~David~~

        I do now... thanks :)

        Unfortunately, this has not changed the output I am getting, it still just prints out $me , $friend, etc.

        Do I need to make a hash named "%var" and put all the scalars in there as keys and values, then update that hash every time I update the scalar?