Jenda Krynicky wrote: > From: "Shawn H. Corey" <shawnhcorey@gmail.com> >> push @{ $r{$h{$_}} }, $_ for keys %h; # one line :) > > Is it simple enough so that you immediately know what does it do? I > guess not. IMHO it's complex enough to warrant being moved to a named > subroutine. Especially since it forces you to write the name of the > original hash twice. > Now, that's not a fair question. Of course I know what it does; I wrote it. But then again I never have to invert a hash; when I populate it, I would populate its inverse as well. I would build both data structures at the same time, inserting only the data I need, where I need it. And no, this would not take more room since you have to have both in memory simultaneously to invert them. It is faster since you don't have to scan the same data again to invert them. Which is why questions like this always seem to be a kludge to me. Someone's manager sees no need to do it right. The problem is kludges are like cancer; they have uncontrolled growth. -- Just my 0.00000002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. My favourite four-letter word is "Done!"Thread Previous | Thread Next