in reply to Bloated code of loops and conditionals
Instead of array refs $data11a, $data11b, etc., make a hash whose keys are 11a, 11b, etc., and store the array refs in it. Then, instead of accessing $data11a->[ $n ] you'd access $data{ 11a }[ $n ]. Or use push to avoid explicit indices.
If you really want to control the valid values for the "goal" parameters, then uncomment the two commented lines. This will cause any record with a "goal" not in this list to be ignored.# my %goals; @goals{ qw( 11a 11b 22 33 ) } = (); my @flds = qw( id title summary ); if ($sqldata) { my %data; for my $d ( @$sqldata ) { my $g = $d->{ 'goal' }; # next unless exists $goals{ $g }; my %h; @h{ @flds } = @{ $d }{ @flds }; # hash slice assignment push @{ $data{ $g } }, \%h; } for my $g ( keys %data ) { $template ->param( "list$g" => $data{ $g } ); } }
Update: Filled in the details. Fixed typo pointed out by bradcathey.
the lowliest monk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Bloated code of loops and conditionals
by bradcathey (Prior) on Apr 23, 2005 at 00:07 UTC | |
by tlm (Prior) on Apr 23, 2005 at 00:31 UTC |