Re: Using Constants as Hash Keys

Stuart Johnston <[email protected]> Thu, 29 Nov 2012 11:11:55 -0600
Newsgroups gmane.comp.lang.perl.modules.template-toolkit
Message-ID <[email protected]>
On 11/29/2012 4:24 AM, Dave Howorth wrote:
> Stuart Johnston wrote:
>> Trying to use a constant as a hash key gives this error: "unexpected
>> token (.)".
>>
>> Here is what I am trying to do:
>>
>> [% { constants.foo => "value" } %]
>>
>> This works but is a bit ugly:
>>
>> [% { ${constants.foo} => "value" } %]
>>
>> Any other suggestions?
>
> I don't understand what you are trying to do. What are the braces for?

It is a hashref. I just trimmed it down to the minimum that causes the 
error. To be more clear:

[% x = { constants.foo => "value" } %]

Or:

[% function({ constants.foo => "value" }) %]

It works fine as an arrayref so currently I am just converting it back 
to a hash on the perl side.