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:
$big_foo_bucket->{camshaft} = $other_foo_bucket{camshaft};
$big_foo_bucket->{gearbox} = $other_foo_bucket{gearbox1};
$big_foo_bucket->{drivetrain} = $other_foo_bucket{the_drivetrain};
$big_foo_bucket->{smokestack} = $other_foo_bucket{my_smokestack};
$big_foo_bucket->{junkyard} = $other_foo_bucket{_junkyard};
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:
@{$big_foo_bucket}{qw[
camshaft gearbox drivetrain smokestack junkyard
]} = @other_foo_bucket{qw[
camshaft gearbox1 the_drivetrain my_smokestack _junkyard
]};
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:
schlep(\%other_foo_bucket => $big_foo_bucket,
qw[
camshaft camshaft
gearbox1 gearbox
the_drivetrain drivetrain
my_smokestack smokestack
_junkyard junkyard
]);
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?