At 2:47 PM on 21 Oct 2009, Travis Basevi wrote:

> Sorry to bring this up from a year ago, but this problem is still 
> annoying me with miles of entries in my apache error logs, and I was 
> wondering if anyone had any simple solution to avoid it?

You could add '|| 0' to the Template code, wherever it does a numeric
operation.  That may be quite a few places...

That would cover the case where the value is blank... but not other
non-numeric values, like trying to add 1 to 'sheep'.  Another
alternative would be adding a function to replace all non-numeric
values with zero, and use that instead of '|| 0'.

Of course, this would all require getting to know the code inside the
Template modules.

FWIW, I agree with your point that Template itself should avoid these
warnings on behalf of the template authors.  It already does so for
undefined values, so non-numerics seems like a natural extension of
that idea.

Here's an example of that function to replace non-numerics.  The regex
may need some tuning:

sub replace_non_numeric {
        my ( $val ) = @_;
        if ( $val !~ /^-?\d*[.e]?\d+$/ ) {
                $val = 0;
        }

        $val;
}


> Travis Basevi wrote:
> > Er, yeah, I'm fully aware of that. That example isn't real-world
> > usage, it's just an illustration of the problem at the simplest
> > level.
> > 
> > The point is that a TT2 coder shouldn't have to write at the level
> > of a hardcore Perl "use strict use warnings" coder to avoid these
> > warnings. And that's ignoring the point that the functionality of
> > TT2 has changed somewhere between 2.14 and 2.19 because of (I
> > suspect) the introduction of "use warnings" in the various modules.
> > 
> > Bill Ward wrote:
> >> Well, it's not numeric, is it?
> >>
> >> On Wed, Oct 22, 2008 at 6:13 AM, Travis Basevi
> >> <tra...@cricinfo.com <mailto:tra...@cricinfo.com>> wrote:
> >>
> >>     I've just upgraded from TT 2.14 to 2.19 as part of a debian
> >> upgrade from etch to lenny, and I can't stop warnings appearing in
> >> the apache logs with something as simple as:
> >>
> >>     [% 1 + "" %]
> >>
> >>     giving: Argument "" isn't numeric in addition (+) at ...
> >>
> >>     This never happened in v2.14, is it to be expected now? Or is
> >> there now an option for turning off these warnings?
> 
> 
> 
> 
> 
> This email, including attachments may be privileged, confidential and
> is intended exclusively for the addressee. The views expressed may
> not be official policy, but the personal views of the originator. If
> you have received this email in error please notify the sender and
> delete it from your system.  Emails are not secure and may contain
> viruses.  No liability can be accepted for viruses that might be
> transferred by this email or any attachment.
> 
> 
> _______________________________________________
> templates mailing list
> templates@template-toolkit.org
> http://mail.template-toolkit.org/mailman/listinfo/templates






-- 

C. Chad Wallace, B.Sc.
The Lodging Company
http://www.skihills.com/
OpenPGP Public Key ID: 0x262208A0

Attachment: signature.asc
Description: PGP signature

_______________________________________________
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to