Re: Transforming HoA into AoH
On Oct 31, 2005, at 12:34, Xavier Noria wrote:
sub HoA_to_AoH {
my ($HoA) = @_;
my @keys = keys %{$HoA};
return [] if not @keys;
my @AoH = ();
my $nkeys = @keys;
my $nvals = @{$HoA->{$keys[0]}};
my $iter = indexes($nvals, $nkeys);
while (my $idxs = $iter->()) {
my %H = ();
my $i = 0;
for my $k (@keys) {
$H{$k} = $HoA->{$k}[$i];
++$i;
}
push @AoH, \%H;
}
return \@AoH;
}
Sorry, there's a bug there (I forgot to use $idxs):
sub HoA_to_AoH {
my ($HoA) = @_;
my @keys = keys %{$HoA};
return [] if not @keys;
my @AoH = ();
my $nkeys = @keys;
my $nvals = @{$HoA->{$keys[0]}};
my $iter = indexes($nvals, $nkeys);
while (my $idxs = $iter->()) {
my %H = ();
my $i = 0;
for my $k (@keys) {
$H{$k} = $HoA->{$k}[$idxs->[$i]];
++$i;
}
push @AoH, \%H;
}
return \@AoH;
}
.
Relevant Pages
- Re: sort-like syntax
... use strict; ... push @res,; ... my @keys = keys %hash; ... (comp.lang.perl.misc) - new laptop: number 1 key is stuck
... i have recently bought a Toshiba L500 (Australian model) and played for ... awhile and have realised the number 1 keys is hard to push, ... (microsoft.public.windows.vista.hardware_devices) - Re: Function key press across network, how?
... I find fingers are very useful for pushing keys, and if your friends ... to push the keys, if such a thing would be practical. ... (comp.programming) - Re: OT: Is a stuck car accelerator capable of doing this?
... particular model does not have an ignition switch but rather a ... keyless system where to shut it down you push the "start" button for ... You should be able to push the button off, or, ... Heh,I can picture you explaining to the rental agency why you don't have the keys to their car...... ... (alt.home.repair) - Re: Ramrod R.I.P.
... The just and the crippled both push up the flowers ... When you tell them you got the keys to the rain? ... (rec.music.gdead) |
|