Clear questions and runnable code
get the best and fastest answer
Bulk Hash Assignmentby tadman (Prior)
|on Apr 17, 2002 at 07:33 UTC
When moving data around, especially from one hash to another, things can tend to get a little bogged down in the details. Programming degrades into a frenzy of cutting and pasting, replacing, and so forth. I keep seeing these heavy heaps of code which, functionally, do almost nothing:
Now, you can't just blind assign one to the other, since one is a ref and the other is a real hash, and the names differ slightly. Also, there is stuff on both sides that isn't meant to be touched. Isn't there a better way to specify the mapping?
The first thing that comes to mind is using slices to swap data, and with a bit of polish, you get something like this:
Yet the results from a structural and scalability perspective aren't entirely satisfactory. The two lists that must be maintained in parallel or Bad Things happen. Further, when you start to add many things to the list, it's either going to scroll or wrap, both of which lead this to be a self-defeating solution.
Ideally, you could use a function to do this, the implementation of which is really quite simple, but at the expense of being non-standard:
Now this works, but seems highly unorthodox, which would probably mean that it's some Dark form of Laziness that you're supposed to keep to yourself.
Surely there is some kind of gasket function which can make this really clean and simple?