[sf-perl] Happy fun sorting problem

Lee, Weng (MSCIBARRA) Weng.Lee at mscibarra.com
Fri Jun 10 09:54:09 PDT 2005


 


>I can think of a few ways to solve this issue, but none that are
elegant.  I'm looking for elegant.
>But this is completely in perl. What's the standard way of dealing with
this?  Hashes of hashes?
If there is a standard way of dealing with anything in Perl, that
wouldn't be Perl,right?
One dirty way I find myself always doing in such situation is to
concatenate the Categories and Keys to form a new Key.
Then sorting will be simple for me.  


>To further complicate things, the "Category" level is being sorted
according to an external ordering list and not alphabetically.
To handle this, I would translate 'Category' level to a number
corresponding to the external ordering list when constructing the key.
To get retrieve the information, I would parse out the concatenated key,
and translate the 'category' level from the ordering number to its'
original form.





I have a 3-level heirarchy:

Category
	Sub Category
		Item = Value

I want to print output that formats like:

Category-1
	Sub Category-H
		Item_a = Value
		Item_f = Value
	Sub Category-S
		Item_d = Value
Category-2
	Sub Category-B
		Item_k = Value
...etc...

The idea being to group by sorted category, then by sorted subcategory,
then sort the items on their keys within that.  The Items happen to be
unique, but I'm not sure that makes a difference to the problem.  

Inside a database, I would just query and sort.   

--
Josh Berkus
Aglio Database Solutions
San Francisco
_______________________________________________
SanFrancisco-pm mailing list
SanFrancisco-pm at pm.org
http://mail.pm.org/mailman/listinfo/sanfrancisco-pm 
--------------------------------------------------------
 
NOTICE: If received in error, please destroy and notify sender.  Sender does not waive confidentiality or privilege, and use is prohibited. 
 


More information about the SanFrancisco-pm mailing list