in reply to In seach of a more elegant foreach
But, to use that set of functions, you need to change your data structure into something that is more easily handled. Warning - the variables are poorly named. But, it is tested.
my @x; my $curr = ''; my @curr; foreach my $ref (@$matrix_ref) { my $k = $ref->[0] . $ref->[1]; unless ($curr eq $k) { push @x, [ @curr ] if @curr; @curr = @$ref; $curr = $k; next; } push @curr, $ref->[2]; } push @x, [ @curr ]; use CGI qw( :all ); $html_str = table( map { Tr( td( $_ ) ) } @x );
------
We are the carpenters and bricklayers of the Information Age.
Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose
I shouldn't have to say this, but any code, unless otherwise stated, is untested
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: In seach of a more elegant foreach
by kiat (Vicar) on Jun 16, 2004 at 02:40 UTC |