in reply to Re^2: Need to turn off prints from module
in thread Need to turn off prints from module
warnings are lexically scoped so, for that solution to work you'd need to modify version.pm. JavaFan was spot on (below) - if you're interested, check the Parse::HTTP::UserAgent source code: in sub _numify you'll find the line my $rv = version->new("$v")->numify;.
Anyway, not being someone who likes to be beaten by zeros and ones, here's a workaround. Before the line:
my $ua = Parse::HTTP::UserAgent->new($useragent);
add
$useragent =~ s{ ( [+] ) [[] [^]]+ []] ( [+] ) }{$1$2}msx;
I ran a few tests with this and it seems to work fine. The test code and output is below (click on Read more...).
Test code:
#!perl use strict; use warnings; use Parse::HTTP::UserAgent; my @useragent_list = ( q{Mozilla/4.06+[en]+(WinNT;+I)}, q{Opera/9.80 (Windows NT 5.1; U; en) Presto/2.6.30 Version/10.61}, q{Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.4) Geck +o/20091016 Firefox/3.5.4}, q{Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525. +28 (KHTML, like Gecko) Version/3.2.2 Safari/525.28.1}, ); for my $useragent (@useragent_list) { print q{UA: }, $useragent, qq{\n}; $useragent =~ s{ ( [+] ) [[] [^]]+ []] ( [+] ) }{$1$2}msx; my $ua = Parse::HTTP::UserAgent->new($useragent); print $ua->name, qq{\n}; print $ua->version, qq{\n}; print $ua->os, qq{\n}; }
Output:
$ ver_overload_prob.pl UA: Mozilla/4.06+[en]+(WinNT;+I) Netscape 4.060 Windows NT UA: Opera/9.80 (Windows NT 5.1; U; en) Presto/2.6.30 Version/10.61 Opera 10.610 Windows XP UA: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.4) Gecko/ +20091016 Firefox/3.5.4 Firefox 3.005004 Windows XP UA: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.28 + (KHTML, like Gecko) Version/3.2.2 Safari/525.28.1 Safari 3.002002 Windows XP
-- Ken
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Need to turn off prints from module
by Mushka (Acolyte) on Nov 17, 2010 at 22:53 UTC | |
by kcott (Archbishop) on Nov 17, 2010 at 23:40 UTC |
In Section
Seekers of Perl Wisdom