geektron has asked for the wisdom of the Perl Monks concerning the following question:
basically, i have a handful of routines that pull values out of a database and create an anon array of hashrefs to pass into HTML::Template:
and so on.sub _getBuilderList { my $self = shift; my $selection = shift; my $sth = $self->param('DBH')->prepare("SELECT id, buildername + FROM builder ORDER BY buildername" ); $sth->execute(); my $cities; while ( my $row = $sth->fetchrow_hashref() ) { $row->{SELECTED}++ if $row->{id} == $selection; push @$cities, $row; } return $cities; } sub _getSchoolList { my $self = shift; my $selection = shift; my $sth = $self->param('DBH')->prepare("SELECT schoolname FROM + school ORDER BY schoolname" ); $sth->execute(); my $cities; while ( my $row = $sth->fetchrow_hashref() ) { $row->{SELECTED}++ if $row->{schoolname} eq $selection +; push @$cities, $row; } return $cities; } sub _buildGenericSelect { my ( $self, $max, $selection ) = @_; my $array; foreach my $number ( ( 1 .. $max ) ) { my $row; $row->{VALUE} = $number; $row->{SELECTED}++ if $number == $selection; push @$array, $row; } return $array; }
the end result is a select menu using the anon array as a TMPL_LOOP
some of them use name as the option value, others use a numeric value ... ( the data's a mess, but it's coming from another datasource ... )
i wonder if there's a quicker way to do it (rather than to keep creating a new 'accessor' every time.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: abstraction -- level up!
by sacked (Hermit) on Jun 16, 2004 at 18:24 UTC | |
|
Re: abstraction -- level up!
by dragonchild (Archbishop) on Jun 16, 2004 at 18:19 UTC | |
|
Re: db -> HTML::Template abstraction abstraction -- level up!
by Sifmole (Chaplain) on Jun 16, 2004 at 17:59 UTC | |
|
Re: abstraction -- level up!
by eric256 (Parson) on Jun 16, 2004 at 18:08 UTC | |
by geektron (Curate) on Jun 16, 2004 at 18:13 UTC | |
by jeffa (Bishop) on Jun 16, 2004 at 18:58 UTC | |
by geektron (Curate) on Jun 16, 2004 at 23:07 UTC | |
by jeffa (Bishop) on Jun 17, 2004 at 14:42 UTC | |
| |
|
Re: abstraction -- level up!
by jZed (Prior) on Jun 16, 2004 at 19:21 UTC |