The for version does omit a step, but at the cost of a lot of calls to print. The map version only calls it once. Thinking about it, you can even pull that call entirely out of the loop:print join "\n", split(/\0/, $dbm{$key}), '';
The double foreach version is the least memory intensive; the no foreach version is most so. But, it is trivial to replace the print then:print map "$_\n", split /\0/, @dbm{sort keys %dbm};
my $cache = freeze [ map "$_\n", split /\0/, @dbm{sort keys %dbm} ];
It wouldn't have been quite so trivial a transition with the double foreach code. That's why I prefer, and believe it is generally preferrable, to build large structures and process them all at once, rather than nibble at bits of them. All data is in once place at every step of the process, and its internal correlations don't get lost.
I'm not going to worry about memory either so long as I have no indication that it's going to become a problem. If and when it does, Perl's tying mechanism makes it easy to opt for the harddisk anyway.
Makeshifts last the longest.
In reply to Re^2: Splitting a hash
by Aristotle
in thread Splitting a hash
by sulfericacid
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |