The following seems to work for anything except references to subroutines (maybe another monk can figure out how to get around that, if it's important to you).

This assumes that the strings returned from your database actually do use single quotes in a consistent way around the citations of variables. (The snippet below demonstrates that references to subroutines do not work the way you'd want.)

#!/usr/bin/perl use strict; use warnings; my %in; my %out; my $testsub; my $constant = "fixed"; $in{cid} = 12345; $out{this}{that}[0] = 678; $testsub = sub { return "this is foobar" }; print "normally, \$testsub returns: " . &$testsub . "\n\n"; while (<DATA>) { s/(?<=')(\$[^']+)/(ref($1) eq 'CODE') ? &{$1} : $1/ee; print; } __DATA__ select field from table where id!='$in{cid}' update table set field = null where id = '$out{this}{that}[0]' delete from table where value = '$constant' select something from somewhere where status='$testsub'
Here's what I get when I run that:
normally, $testsub returns: this is foobar select field from table where id!='12345' update table set field = null where id = '678' delete from table where value = 'fixed' select something from somewhere where status='CODE(0x7ff80903f0e8)'
UPDATE: Just to be clear about the subroutine reference problem: I get the same output with this simpler substitution:
s/(?<=')(\$[^']+)/$1/ee;
I've tried a few variations in the DATA line(&$testsub etc.), but to no avail.

In reply to Re: How to interpolate sql-output by graff
in thread How to interpolate sql-output by Seq

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.