> This is not actually TT question, but maybe there's a good way to solve
> this in TT. Let's assume i have following hash:
> 
>    header_data => [
>    {  image_on => 'adm_menyp.gif',
>       image_off => 'adm_menyp.gif',
>       image_alt => '[ menu ]',
>       name => 'menu',
>       href => 'menu.html',
>       links => [
>       {  href => 'link1.html', nimi => 'Link 1 name' },
>       {  href => 'link2.html', nimi => 'Link 2 name' },
>       ]
>    },
>  ]
> 
> Ok, now i want to generate my page's header from this, basically
> just href is main category and links.href's are sub-categories.
> Problem is that if my link looks like http://myserv.org/link1.html
> (subcategory), then i don't know under which category it belongs to :(.
> Now is there a simple way to find it out? Yeah, i could loop through
> header_date and see which links.href matches, but i don't like it. Is
> there something like 'parent' or whatever (like in JavaScript) in TT, or
> better, in perl?

No.  A hash gives you a one-way map of keys to values.  Other than
searching (which could be done quite concisely, if not quickly) you
could:

  - add some side information to your link (eg: an extra parameter)
    that tells you which category the link belongs to, or

  - the code that generates header_data could easily generate a reverse
    mapping hash of values to keys (assuming it is one-to-one), or in
    your case, values to category.  Then you just have a simple hash
    lookup.  You also have to be careful about untethered circular
    references causing memory leaks.

Craig


Reply via email to