Subject: | suppress spurios warnings |
Hiya,
I'm running into a small problem with the warning output of HTTP::BrowserDetect -- it's making the output of my test scripts difficult to read due to the number of warnings generated. This will also clutter up log files, and I'd rather avoid that if possible.
For example, this program:
use HTTP::BrowserDetect;
my $ua = 'Internet Explorer 6 (MSIE 6; Windows XP)';
my $bd = HTTP::BrowserDetect->new;
$bd->user_agent( $ua );
Produces these warnings:
Use of uninitialized value in concatenation (.) or string at /usr/local/lib/perl5/site_perl/5.8.4/HTTP/BrowserDetect.pm line 118.
Argument "." isn't numeric in addition (+) at /usr/local/lib/perl5/site_perl/5.8.4/HTTP/BrowserDetect.pm line 118.
Use of uninitialized value in index at /usr/local/lib/perl5/site_perl/5.8.4/HTTP/BrowserDetect.pm line 176.
Use of uninitialized value in numeric eq (==) at /usr/local/lib/perl5/site_perl/5.8.4/HTTP/BrowserDetect.pm line 185.
Use of uninitialized value in numeric eq (==) at /usr/local/lib/perl5/site_perl/5.8.4/HTTP/BrowserDetect.pm line 186.
Use of uninitialized value in numeric ge (>=) at /usr/local/lib/perl5/site_perl/5.8.4/HTTP/BrowserDetect.pm line 187.
Use of uninitialized value in numeric eq (==) at /usr/local/lib/perl5/site_perl/5.8.4/HTTP/BrowserDetect.pm line 188.
Use of uninitialized value in numeric ge (>=) at /usr/local/lib/perl5/site_perl/5.8.4/HTTP/BrowserDetect.pm line 189.
Use of uninitialized value in numeric eq (==) at /usr/local/lib/perl5/site_perl/5.8.4/HTTP/BrowserDetect.pm line 190.
Use of uninitialized value in numeric ge (>=) at /usr/local/lib/perl5/site_perl/5.8.4/HTTP/BrowserDetect.pm line 191.
Use of uninitialized value in numeric eq (==) at /usr/local/lib/perl5/site_perl/5.8.4/HTTP/BrowserDetect.pm line 192.
Use of uninitialized value in string eq at /usr/local/lib/perl5/site_perl/5.8.4/HTTP/BrowserDetect.pm line 370.
Most of these can be avoided by making sure the vars are initialized -- see attached patch.
hth,
-Steve
diff -ru HTTP-BrowserDetect-0.98.orig/BrowserDetect.pm HTTP-BrowserDetect-0.98/BrowserDetect.pm
--- HTTP-BrowserDetect-0.98.orig/BrowserDetect.pm Sun Nov 21 22:16:00 2004
+++ HTTP-BrowserDetect-0.98/BrowserDetect.pm Sun Nov 21 22:55:21 2004
@@ -7,7 +7,7 @@
@ISA = qw(Exporter);
@EXPORT = qw();
@EXPORT_OK = qw();
-$VERSION = '0.98';
+$VERSION = '0.98_01';
# Operating Systems
push @ALL_TESTS,(qw(win16 win3x win31 win95 win98 winnt windows win32 win2k winxp winme dotnet mac macosx mac68k macppc os2 unix sun sun4 sun5 suni86 irix irix5 irix6 hpux hpux9 hpux10 aix aix1 aix2 aix3 aix4 linux sco unixware mpras reliant dec sinix freebsd bsd vms x11 amiga));
@@ -115,7 +115,12 @@
}
- $minor = 0+".$minor";
+ # avoid spurious warnnings
+ $minor = 0 unless defined $minor;
+ $major = 0 unless defined $major;
+ $beta = '' unless defined $beta;
+
+ $minor = 0 + "0.$minor";
$self->{tests} = {};
my $tests = $self->{tests};
@@ -161,7 +166,13 @@
( [\d]* ) # Minor version nnumber is digits after first dot
( [^\s]* )
/x);
- $minor = 0+".$minor";
+
+ # avoid spurious warnnings
+ $minor = 0 unless defined $minor;
+ $major = 0 unless defined $major;
+ $beta = '' unless defined $beta;
+
+ $minor = 0 + "0.$minor";
#print "major=$major minor=$minor beta=$beta\n";
}
Only in HTTP-BrowserDetect-0.98: BrowserDetect.pm~