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 );
In reply to HTML::Template Modules and Zeros by Angel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |