Main Topics
Browse All TopicsHello, my question is hard to explain but I will do my best,
I am using Perl/MySQL to make a shopping cart system and have a very specific requirement for displaying items.
I have managed to write (and rewrite) a good deal of SQL to get me the values from the database looking the way I want. The next step is to get them into a data structure that I can then send to my template (I'm using HTML::Template)
The best way I can explain myself is through example so here goes..
I want to end up with a data structure looking something like in the code I made up below but the results are to come from the MySQL database which are also in the code below with the SQL statement to produce it, I just need the Perl part to turn it into the other.
In Perl I would be going through the rows one at a time, but am stuck at turning it into the AOH or whatever I need...
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
wow, thats fantastic!! thanks so much
I think I need to understand how to translate this into the HTML::Template now... but there is one important issue which is that I need the order in that middle part of the structure maintained, so a hash of sub_components may not be the best idea.. I tried to turn just that line into an anonymous array but without success, I don't know the right syntax but something like:
sub_components => @[ {$row->{ID} => $row->{p_s_comp} . ' ' . $row->{price}}} ];
then I can step through it as an array and it will maintain the order it comes from the DB (it also is just a coincidence that the ID's are in the same order as the prices)...
I am very impressed with the quality & response here thanks... but I am not quite there with the data structure... I think I was getting ahead of myself trying to predict the exact data structure I needed. I have found this page:
http://www.perlmonks.org/i
which shows pretty much what I'm after in the data structure which is almost the same as you have done(wish I found that before I posted here!!) , but I've tried to tweak it to match their example but HTML::Template keeps complaining:
"HTML::Template->output() : fatal error in loop output : HTML::Template->output() : fatal error in loop output : HTML::Template->param() : Single reference arg to param() must be a hash-ref! You gave me a ARRAY. at /HTML/Template.pm line 3068"
I have a datadump of the structure below in the code as well - notice how the first array in the subcomponent is missing, its just a hash...
I also changed the subcomponents to accommodate HTML::Templates need for hash-refs but don't know if I got it right, obviously not eh :)
Business Accounts
Answer for Membership
by: timbo007Posted on 2009-10-22 at 07:56:42ID: 25634974
One thing which is an option is that the column I am wanting to group from ( p_comp ) are just sitting in that column with no reference from anywhere else, ie there is no ID number or anything associated with each set of p_comp's where as I could move that whole column into another table with ID's and then reference the ID's so that the grouping would be done using numbers not random text... is that a good idea?