Cyril Cheneson wrote:
> Hi all,
> 
> I m passing a has ref to a template.
> In this hash, there can be a value which is pointing to an array ref,
> or hash ref.
> Is there any way to find out, from the template, if the value of a
> variable is an array, hash, scalar just like the ref() in perl?
> 
> I used size() but for a scalar, size() returns 1.

One way is to use vmethods that are only associated with certain types.
ie: to detect a
*) hash use .keys and see if it returns a number.
*) scalar: length

You could roll your own ref vmethod or pass a routine via vars to do it.

This has been discussed before a few times on the list. It almost should be in 
the main distribution even though I know the idea is to keep knowledge of that 
type of thing away from the user. I certainly wouldn't mind seeing it in the 
main distribution, though.

-- Josh Rosenbaum

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

Reply via email to