in reply to Splitting a hashref into hashrefs

One hashref won't work? Why the heck not? Clearly these things represent a single record, since you selected them with a join. Separate hashrefs would mean these things are not related.

Replies are listed 'Best First'.
Re: Re: Splitting a hashref into hashrefs
by legLess (Hermit) on Mar 20, 2003 at 08:19 UTC
    One of my explicit goals is to make the HTML templates as easy to use as possible. I hold that this template:
    <p>Org id: [% org.id %]</p> <p>Org name: [% org.name %]</p> <p>Group id: [% group.id %]</p> <p>Group name: [% group.name %]</p>
    ...is more intuitive and easier to use than this one, which is what I need if I use a single hashref:
    <p>Org id: [% hashref.org_id %]</p> <p>Org name: [% hashref.org_name %]</p> <p>Group id: [% hashref.group_id %]</p> <p>Group name: [% hashref.group_name %]</p>
    My other goal is to learn a few other ways of doing this, perhaps even a cool way to split a hashref into two hashrefs.

    Most of this is copied from my post; perhaps you should have read it more carefully?
    --
    man with no legs, inc.
      I read it and understood; I just don't agree with your ideas about data structures for templating. I believe you should only nest your data structures when the data actually requires it, which is not the case here. If I were doing this, I would get rid of that top hashref and set it up like this:
      <p>Org id: [% org_id %]</p> <p>Org name: [% org_name %]</p> <p>Group id: [% group_id %]</p> <p>Group name: [% group_name %]</p>
      I would only use another level below this if there are multiple values. For example, if there are multiple groups per organization, I would represent groups as an array of hashes, so I could make a template like this:
      <p>Org id: [% org_id %]</p> <p>Org name: [% org_name %]</p> [% FOREACH group = groups %] <p>Group id: [% group.id %]</p> <p>Group name: [% group.name %]</p> [% END %]
        Thanks for the additional reply, and for being a bit more explicit in your disagreement. We'll have to agree to disagree, I think.

        There are many places in the templates where I do have multiple items and do require Template::Toolkit's dot.notation. I think it's better (and easier for the template maintainer) to be consistent by always using hashes than to switch between hashes and scalars.

        The point of my post wasn't to argue about my templating (although this is fine, really, and has given me some additional ideas to chew on), but to find a way to make the code do what I wanted. So far no one's touched upon my original question as indicated by my title; I'll try again.
        --
        man with no legs, inc.