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.

# 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 } ); } }
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.

Update: Filled in the details. Fixed typo pointed out by bradcathey.

the lowliest monk


In reply to Re: Bloated code of loops and conditionals by tlm
in thread Bloated code of loops and conditionals by bradcathey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.