so, given an object like this:package MySample; sub build_dropdown { # build_dropdown( \$DataObject , 'key_function', 'text_functi +on', 'Select A Header', 'preselectedValue' ); my @xml; if ( $_[3] ) { push @xml , qq{<option value="">$_[3]</option>}; push @xml , qq{<option value="">==========</option>}; } foreach my $id ( $_[0]->{$_[1]}() ) { my $sel = ( $id == $_[4] ) ? ' selected' : ''; push @xml , ("<option value=\"$id\"${sel}>" . $_[0]->{$_[2 +]}($id) . '</option>'); } return join "\n" , @xml; }
I could just do thispackage myBox; sub new { my $proto = $_[0]; my $class = ref($proto) || $proto; my $self = bless ( {} , $class ); $self->{'__keys'} = { '1' => 'a', '2' => 'b', '3' => 'c', +'4' => 'd', '5' => 'e' }; return $self; } sub get__keys { return keys %{ $_[0]->{'__keys'} }; } sub get__textforkey { return $_[0]->{'__keys'}{$_[1]} ; } 1;
unfortunately, I can't scope/write the function calls right . can anyone help me with this?my $box = myBox->new(); print &HtmlDropDowns::build_dropdown( $box , 'get__keys' , 'get__t +extforkey' , 'select a header' , 2 );
In reply to Assistance in abstracting a common routine by nmerriweather
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |