develooper Front page | perl.beginners | Postings from August 2009

Re: Inverting a hash safely

Thread Previous | Thread Next
Shawn H. Corey
August 4, 2009 06:53
Re: Inverting a hash safely
Message ID:
Ed Avis wrote:
> Shawn H. Corey <shawnhcorey <at>> writes:
>> Why on earth would you want to invert an XML file?
> What I mean is that many modules (such as XML::Twig) return data as hashes.
> To me, it doesn't make any sense to return both a hash and its inverse from
> the function.  Instead I would return just one hash.

But why?  An XML file contains two parts: mark-up and content.  To have 
the mark-up as the key and the content as the value makes sense.  For 
example, if you want to find the publication date, you look for the key 
'publication_date'.  To invert such a hash would mean you want to find 
the markup for the content.  For example, you could ask, what is the 
markup for 'Aug. 4'?  Sure, you can get the information but what are you 
going to use it for?  The only possible reason for doing this is that 
someone tried to be clever and stuffed some content into the markup, 
which now has to be extracted (and you already know my opinion on clever :).

To me, inverting a hash is just another round of Perl Golf, not 
something I would use in Real Code. ;)

Just my 0.00000002 million dollars worth,

Programming is as much about organization and communication
as it is about coding.

My favourite four-letter word is "Done!"

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About