Think about Loose Coupling | |
PerlMonks |
Re: Specific hash to array conversion queryby Zaxo (Archbishop) |
on Jul 12, 2005 at 03:06 UTC ( [id://474158]=note: print w/replies, xml ) | Need Help?? |
Interesting challenge to build that with map. The difficulty is that the expansions will need to be somewhat inside-out. Lets try building it one step at a time, outside-in. Given %properties, we need to work first with its keys, since their names are part of the output. So, my @values = map { foo( $_) } keys %properties; where foo() takes a key of %properties and returns a list of array references taken from that key. Making an actual sub foo() for that is probably not justified, so we'll expand foo's definition in place, bar() is just like foo(), but it has more arguments to help build our array references. In fact, bar() has all the arguments we need, so we expand it again, There it is, with map, all in one statement. That doesn't bother to sort the keys, but if you want that, you can insert it,
It's a good idea to avoid one-lining constructions like this. It makes them very hard to read if you skip indentation. After Compline,
In Section
Seekers of Perl Wisdom
|
|