I ended up going with the following:
sub DisplayFields { my ($screen,$screenname,$tabdata,$fields) = @_; for (my $i = 0; $i < @$fields; $i+=2) { my ($field,$style) = ($$fields[$i+1]->[1],''); if ($field eq 'textfield') { $field = $cgi->textfield( -name => @$fields[$i], -size => @$fields[$i+1]->[2], -default => $$tabdata->{$screenname}->{@$fields[$i]}, ); } elsif ($field eq 'picklist') { $field = $cgi->popup_menu( -name => @$fields[$i], -values => @$fields[$i+1]->[2], -labels => @$fields[$i+1]->[3], -default => $$tabdata->{$screenname}->{@$fields[$i]}, ); } elsif ($field eq 'checkbox') { $field = $cgi->checkbox( -name => @$fields[$i], -value => 1, -label => '', -checked => $$tabdata->{$screenname}->{@$fields[$i]}, ); } elsif ($field eq 'textarea') { $style = 'vertical-align: top'; $field = $cgi->textarea( -name=> @$fields[$i], -rows => @$fields[$i+1]->[2], -columns => @$fields[$i+1]->[3], -default => $tabdata->{$screenname}->{@$fields[$i]}, ); } if ($field eq 'begin_table') { $$screen->AppendToSection('body',qq(<table class="@$fields +[$i+1]->[2]"><tr><td>&nbsp;</td></tr>)); } elsif ($field eq 'end_table') { $$screen->AppendToSection('body','</table>'); } else { $$screen->AppendToSection('body',qq(<tr><td class="fieldna +me" style="$style">@$fields[$i+1]->[0]</td><td class="fieldvalue">$fi +eld</td></tr>)); } } }
So now in my 'tabs', (this is through a web browser don't ask how :p) I can neat things like:
sub CoreModuleInfoTabEdit { my($module,$tabdata,$screen) = @_; SetupStyles(\$screen); DisplayFields(\$screen,'CoreModuleInfo',\$tabdata,[ begin_table => ['','begin_table','config'], exit_url => ['Exit URL','textfield',50], session_expire_time => ['Session Expire Time (minutes)', +'textfield',4], session_max_time => ['Session Max Time (hours)','textfie +ld',4], allow_guest_login => ['Allow Guest Logins','checkbox','' +], end_table => ['','end_table',''], ]); }
(in the app i'm working on each subroutine is a different tab, and there's a complex management system that works completely behind the scenes to manage the user's navigation through the tabs)... This works great for me, before I had two screens that totaled 415 lines, after this, both screens plus the display routine totaled 123 lines :) Mmmmm, Diet Code(TM)...

Thanks Fastolfe!

In reply to Re: Re: Hashes/Scalars and Memory Usage by EvilTypeGuy
in thread Hashes/Scalars and Memory Usage by Anonymous Monk

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.