On Thu, Nov 13, 2008 at 10:58 AM, Todd Rinaldo <[EMAIL PROTECTED]> wrote:

> My question: Is there any easy way to make a recursive block that can
> test if an unpredictably deep hash is defined?
>

Perhaps, but it would be easier to write a routine in Perl:

sub nested {
  my ($hash, @keys) = @_;
  for my $key (@keys) {
    return if ref $hash ne 'HASH' || !exists $hash->{$key};
    $hash = $hash->{$key};
  }
  return 1;
}

Provide the function to your template, and then you could say:

[% NEXT IF !nested(hash, 'fi', 'fo', 'fum', 'bar') %]

Alternately, you could make it a new hash vmethod.


--Sean
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to