Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: loop through a hash structure without knowing the hash keys?: msg#00011

lang.perl.modules.html-template

Subject: Re: loop through a hash structure without knowing the hash keys?

Boon Chew wrote:
> It might be difficult to do for multilevel nested data structure, but I
> think having support for one of the most common data structure, array of
> hash, is a good start, because array of hash mirrors the structure of a
> resultset coming back from a DB query.

You're reading my mind.

First off, multilevel nested data structures are quite doable. I just
posted an idea for getting H::T to handle normal lists, lists of
lists, lists of lists of lists, etc. As I mentioned, I also have some
ideas for handling hashes, at which point you can handle lists of
hashes, hashes of lists, hashes of hashes of lists of lists of hashes,
or whatever other insane combination you might choose. Admittedly, I
see few uses for anything beyond ordinary lists, lists of lists, and
lists of hashes; but that's (literally) another topic.

But lists of hashes do hold a special status, due to their similarity
to database tables: I wouldn't be averse to an extension to H::T that
lets you use SQL SELECT queries as substitutes for loop control
variables, letting the template writer merge tables, sort their
contents to his liking, filter out unwanted records, or create new,
calculated fields from existing ones. There is value to the notion of
viewing lists of hashes as tables.

> Currently we can use tmpl_loop to loop through the array elements (or
> thinking in terms of DB, the rows), so that's taken care of. What's missing
> is a way to get the hash keys, so maybe there can be a contextual var that
> gives you the hash keys (from the DB perspective, the columns or fields), as
> in __ColumnList__ or something that you can loop through with. Sorry I am
> just thinking out loud here, as I don't know enough about HTML::Template
> internals enough to know that's possible or makes sense.

This capability seems a bit excessive to me; the template designer
should rarely (if ever) have to write a template that needs to find
out for itself about the structure of the data that's being provided
to it. When dealing with DB applications, it's rare that the
application needs to look up the column names; usually, it is told by
the programmer what column names to expect and works with that.

And with H::T, if the template in question really needs to know the
names of the keys of a particular hash, the script writer can
explicitly load them into the template. Part of the H::T design
philosophy is that the template does little more than to look up
pre-processed data and to decide how to dress it up; even the SQL
SELECT suggestion that I made above puts more work into the hands of
the template writer than the basic design philosophy would recommend
(heck, doing simple comparison tests such as "name > 5" is verboten in
the standard form of the application).

--
Jonathan "Dataweaver" Lang


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
qnx.openqnx.dev...    gcc.libstdc++.c...    solaris.opensol...    information-ret...    misc.misterhous...    web.catalyst.ge...    apache.webservi...    redhat.release....    hardware.lirc/2...    kernel.autofs/2...    technology.sust...    linux.vdr/2003-...    editors.lyx.gen...    org.user-groups...    netbsd.devel.pk...    xdg.devel/2004-...    version-control...    jakarta.slide.d...    debian.packages...    creativecommons...    ports.ppc.embed...    bug-tracking.bu...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe