Angel has asked for the wisdom of the Perl Monks concerning the following question:
Dear Fellow Monks,
Back when I was doing simple subtitution s/var_name/$var_name I used a pad function to take the results from a database that were zero but perl insisted were blank scalars and print them as "0"
I am now using HTML::Template and using a Module to query the data my attempts have failed to get "0" on the output. Any ideas I am sure its simple but I have missed something here. And I'd rather not put the padding in the main module
# pad adds leading zeros to a string ### FROM THE MODULE THAT QUERIES THE DATA #### sub pad( ) { my $output; my ($string, $length)=@_; if( $string eq "" ) { $output = "0"; } else { my $padlength=$length-length($string); $output = "0"x$padlength.$string; } return $output; } sub get_number_prereg_adult( $ ) { my $data; my $query; my $self = shift; my $dbh = $self->{dbh}; my $sqlQuery = "SELECT COUNT(*) FROM PREREGDATA WHERE GroupID = $self->{'group_id'} AND Category = \'1\'"; $query = $dbh->prepare( $sqlQuery ); $query->execute() || die $dbh->errstr; if( $data = $query->fetchrow_array() ) { $self->{error_type} = ""; $self->{error_string} = ""; return( pad( $data, 1 ) ); } else { $self->{error_type} = "variable returned no value"; $self->{error_string} = "variable returned no value"; return( undef ); } } ### FROM THE MODULE THAT USES HTML TEMPLATE #set template page $template = HTML::Template->new( filename=>"update_group_informatio +n_template.htm" ); $template->param( number_pre_reg_adult_variable_string => $qu +ery_module->get_number_prereg_adult );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: HTML::Template Modules and Zeros
by dws (Chancellor) on Apr 22, 2003 at 00:19 UTC | |
|
Re: HTML::Template Modules and Zeros
by dragonchild (Archbishop) on Apr 21, 2003 at 22:39 UTC | |
|
(z) Re: HTML::Template Modules and Zeros
by zigdon (Deacon) on Apr 22, 2003 at 17:20 UTC |