Question: I am trying to run a fairly simple count based on two MySQL tables but I can't get the syntax right.

```
         Table_1                                Table_2
Actor | Behavior | Receiver |       | Behavior | Type_of_behavior |
 Eric        a        ann                a            Good
 Eric        b        ann                b            Bad 
 Bob         a        Susan              a            Good
 Bob         c        Bob                c            shy

```

I want to `COUNT Table 1.Behavior` by `table_2.Type_of_behavior WHERE Table_1.Behavior = Table_2 Behavior` and `group by Table_1.Actor`. The syntax I've tried is below.  

I realize I could join the tables, but for other reasons I need them separate. 

```
SELECT actor, JOIN Table_1, Table_2
COUNT(IF(Table_2.Type_of_behavior = "good", 1,0))
 AS 'good' FROM Table_1.Behavior GROUP BY actor;

```

Answer: 
What you have there is called a "template". As such, you are looking for a templating system.

Assuming those quotes aren't actually in the string, the only template system I know capable of understanding that templating language is [String::Interpolate](http://search.cpan.org/perldoc?String%3a%3aInterpolate).

```
$ perl -E'
   use String::Interpolate qw( interpolate );
   my $template = q!This is a string with hash value of $foo->{bar}!;
   local our $foo = { bar => 123 };
   say interpolate($template);
'
This is a string with hash value of 123

```

If the quotes are part of the string, what you have there is Perl code. As such, you could get what you want by executing the string. This can be done using [`eval EXPR`](http://perldoc.perl.org/functions/eval.html).

```
$ perl -E'
   my $template = q!"This is a string with hash value of $foo->{bar}"!;
   my $foo = { bar => 123 };
   my $result = eval($template);
   die $@ if $@;
   say $result;
'
This is a string with hash value of 123

```

I strongly recommend against this. I'm not particularly found of String::Interpolate either. [Template::Toolkit](http://search.cpan.org/perldoc?Template%3a%3aToolkit) is probably the popular choice for templating system.

```
$ perl -e'
   use Template qw( );
   my $template = q!This is a string with hash value of [% foo.bar %]!."\n";
   my %vars = ( foo => { bar => 123 } );
   Template->new()->process(\$template, \%vars);
'
This is a string with hash value of 123

```
This should work:

```
$foo->{"bar"} = 5;
printf "This is a string with hash value of $foo->{\"bar\"}]";

```