Starting, I'm not really sure if this is less of a question than a meditation, though I'll put it here anyways.
Recently, and once in the past, I have run into algorithems where it would be sweet to have a array-ref as a hash-key. I realize this isn't *directly* possible (without having the stringified version of the ref as the key rather than the ref its self), and I am aware of modules on CPAN as well as similar
perlmonk writeups on this issue, though I am seeking the guidance from others who have stumbled across similar situations that may have found a slick way to work with this limitation while not having to install or use any modules to do so.
A major disclaimer being: I am a HUGE fan of programatic data structures. By this I mean I have a tendancy to create static complex data structures that will allow for conditional switching, and cool one-liners to utilize easily modifiable structures rather than having to go back for raw logic changes later; just change the structure.
Real Question:
Now that you've read my little book, here is the situation I ran into recently. Basically, lets say I have one hash
$hash_one. Now, I want to test
$hash_one for key
a,
b,
c, etc. If all three are defined, I want to copy the hash into two new hashes, each with new, yet different sets of defaulted keys. Along the same lines, if different combinations of said keys are defined, I would want to copy the hash
n, each with different default values, etc. Mind again, I didn't want to create any new objects, import any external modules, etc. for this solution.
Therefore, if I we're to have the following data structure:
my $struct = {
[ qw( a b c ) ] => [
{ 'a' => 1, 'b' => 2, 'c' => 3, },
{ 'a' => 0, 'b' => 1, 'c' => 2, }
],
};
I could simply test the hash,
$hash_one, for keys in
[qw(a b c)], all are true, I could then copy
$hash_one for each iteration within the valued array-reference, I could then clobber the values in the newly copied array with that in each of the hash-refs.
Phew! I realize this is pretty wierd, and a very unique situation, and one that is not really all that possible to solve in this manner. However, my 'question' is:
Has anyone else out there ever ran into something like this (or understand what the heck I'm even saying). If so, how did you solve it??
I have found a pretty nifty answer to this problem since, yet it's still one of the only last limitations to Perl that I've had to bang my head against the wall against... and just say to my self "Perl, you can do everything else 10 different ways, except for the one thing I want right now".
Maybe I'm just nuts and need to de-complex my code... hm.
---hA||ta----
print map{$_.' '}grep{/\w+/}@{[reverse(qw{Perl Code})]} or die while ( 'trying' );