[Templates] Hash Keys With Leading Dots

[prev] [thread] [next] [Date index for 2004/11/09]

From: Dave Cash
Subject: [Templates] Hash Keys With Leading Dots
Date: 22:38 on 09 Nov 2004
Hi,

I ran across what looks like a bug to me, though I suppose it could
be a feature.  :)

When a hash key starts with a dot, I can't figure out how to
retrieve its corresponding value from the hash.  Here's a sample
script to illustrate the problem:

-------------------------------------------------------------------
#!/usr/bin/perl

use strict;
use lib '/www/ocms/lib';
use Template;
use Template::Constants qw( :debug );

my $data = {
        '1213.103' => {
                name => 'Sally',
                age  => 21
        },
        '1502.523' => {
                name => 'Tommy',
                age  => 25
        },
        '.109'     => {
                name => 'Kevin',
                age  => 54
        }
};

my $tt = Template->new or die Template->error;

$tt->process( \*DATA, { data => $data } ) or die $tt->error;

__DATA__
[% USE Dumper %]

[% Dumper.dump( data ) %]
[% FOREACH id = data.keys.sort %]
[%      id %]
[%      Dumper.dump( data.$id ) %]
[% END %]
-------------------------------------------------------------------

When id is '.109', data.$id returns nothing.  I was thinking that
maybe a patch to Stash's get() could solve the problem, by first
doing a check to see if they $ident value would return something on
its own, before splitting it and recursing down the dot-separated
parts.  But I had trouble making that work.  Like I said, this may
well be a feature, but it seems strange to me that hash keys with a
non-leading dot work fine; it's only the dot-leading keys that fail
when used in this way.

Any thoughts on how (or whether) to approach a fix?

Thanks,

Dave

/L\_/E\_/A\_/R\_/N\_/T\_/E\_/A\_/C\_/H\_/L\_/E\_/A\_/R\_/N\
Dave Cash                              Power to the People!
Frolicking in Fields of Garlic               Right On-Line!
dave@xxxxx.xxx                                  Dig it all.

_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates

[Templates] Hash Keys With Leading Dots
Dave Cash 22:38 on 09 Nov 2004

Re: [Templates] Hash Keys With Leading Dots
Dylan Hardison 05:15 on 10 Nov 2004

Re: [Templates] Hash Keys With Leading Dots
Andy Wardley 08:50 on 10 Nov 2004

Generated at 08:55 on 15 Mar 2005 by mariachi v0.52