in reply to ordering a hash of arrays by an array contents
sort { $hoa{$a}->[0] cmp $hoa{$b}->[0] } keys %hoa;
Update: An expanded answer:
my @sorted_keys = sort { $hoa{$a}->[0] cmp $hoa{$b}->[0] } keys %hoa; foreach my $row_key ( @sorted_keys ) { print "<tr><td>$row_key:</td>\n"; my $index = 0; foreach my $cell ( @{ $hoa{$row_key} } ) { print "<td>$index = $cell</td>"; $index++; } print "</tr>\n"; }
This sorts the rows by the first element of the arrays within the rows.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: ordering a hash of arrays by an array contents
by Bob H (Initiate) on Oct 03, 2008 at 18:57 UTC |