in reply to Converting HoA into AoH
Your desired output looks more like an AoH. It doesn't have any keys in the top level.
Yet another combinatorial problem. Let's try glob again,
As I say, that returns a reference to an array of hashes.sub hoa2aoh { my $hoa = shift; my @keys = keys %$hoa; my @patterns = map { local $" = ','; "{@$_}"; } values %$hoa; [ map { my %hash; @hash{@keys} = split ','; # char changed from "\0" \%hash; } glob join ',', @patterns ]; }
Update: glob wasn't liking the "\0" seperator I used at first. It didn't like whitespace, either. Changed to comma, it works now. Also removed superfluous variable.
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Converting HoA into HoH
by neversaint (Deacon) on Oct 31, 2005 at 06:35 UTC | |
by Zaxo (Archbishop) on Oct 31, 2005 at 07:21 UTC | |
by neversaint (Deacon) on Oct 31, 2005 at 07:53 UTC | |
by Zaxo (Archbishop) on Oct 31, 2005 at 16:57 UTC |