jaa has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I am a TT newbie, so apologies in advance for what may be obvious to you!

This TT snippet works:

[% # perl - $row->{action} = [qw( a b c )]; dumper.dump( row.action ) %]

But this fails, I assume because the underscore is the TT op for concatination.

[% # perl - $row->{_action} = [qw( a b c )]; dumper.dump( row._action ) %]
How do I access values in TT from a hash where the hashkey starts with underscore?

Many thanks,

Jeff

Replies are listed 'Best First'.
Re: Template::Toolkit - accessing hashes when keys starts with underscore?
by olus (Curate) on May 14, 2008 at 14:18 UTC

    The docs say:

    Any key in a hash which starts with a '_' or '.' character will be considered private and cannot be evaluated or updated from within a template.

    update: but

    You can disable this feature by setting the $Template::Stash::PRIVATE package variable to a false value.
    $Template::Stash::PRIVATE = undef;   # now you can thing._private

Re: Template::Toolkit - accessing hashes when keys starts with underscore?
by jaa (Friar) on May 14, 2008 at 14:15 UTC

    arghh! found this link: http://www.stonehenge.com/merlyn/LinuxMag/col61.html which says

    Keys in hashes that start with underscore or dot are considered private, and may not be accessed by any means.

    So looks like I cannot marry the existing data structures into TT without post-processing... sigh.