I am currently using the template toolkit framework and working with a Perl hash data type in my tt file. My goal is to convert this Perl hash data type into a JavaScript hash data type.
Code: template:
[% PERL %]
use JSON qw(encode_json);
my $vars = {
'version' => 3.14,
'days' => [ qw( mon tue wed thu fri sat sun ) ],
'cgi' => CGI->new(),
'me' => {
'id' => 'abw',
'name' => 'Andy Wardley',
},
};
my $json = encode_json($vars->{'me'});
[% END %]
<script>
function callme(){
var me = [% $json %]
}
</script>
Now, I need to make sure that the "me" hash is accessible in JavaScript.