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

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.