Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Need to turn off prints from module

by kcott (Abbot)
on Nov 17, 2010 at 17:39 UTC ( #872025=note: print w/ replies, xml ) Need Help??


in reply to Need to turn off prints from module

If you can identify the point in the code where this is happening, you can selectively turn off this specific warning type with:

no warnings 'misc'; # problem code here use warnings 'misc';

Be aware this turns off all 'misc' warnings between no warnings 'misc'; and use warnings 'misc';.

If you look in perldiag, you can do a search for 'Version string' which finds:

Version string '%s' contains invalid data; ignoring: '%s'
(W misc) The version string contains invalid characters at the end, which are being ignored.

The "(W misc)" tells you which warning to turn off.

perllexwarn describes all the warning types.

-- Ken


Comment on Re: Need to turn off prints from module
Select or Download Code
Re^2: Need to turn off prints from module
by Mushka (Acolyte) on Nov 17, 2010 at 18:27 UTC
    Thank you all!

    Ken, i love your suggestion - this is exactly what i'm looking for. I tried putting no warnings 'misc'; just before i start using the module in my $ua = Parse::HTTP::UserAgent->new($useragent); and said to use warnings after all the parsing is done, but that doesnt change anything - i still see those pesky lines. :o( I also tried no warnings; and that didnt help either.

    Looking forward to more ideas!

      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...).

      -- Ken

        Thank you Ken! I thought of this workaround too, and it works marvelously for "[en]" issue, but those were not the only user agent strings that the module was notifying me about.

        For example, string
        Mozilla/5.0+(Windows;+U;+Windows+NT+5.1;+en-US;+rv:1.9.1.15)+Gecko/20101026+Firefox/3.5.15+(.NET+CLR+3.5.30729)
        gives me a warning
        Version string '20101026Firefox.0' contains invalid data; ignoring: '20101026Firefox.0' at /usr/local/share/perl/5.8.8/Parse/HTTP/UserAgent.pm line 210, <FILES> line 26.

        That's why i was asking a more global question how to "shut that module up". :o) I was thinking along the lines how you can say 2>&1 perhaps you could send all output from specified module to /dev/null... I would love to go into the module and tweak it, but i have read-only privileges, and i would try to avoid bothering the person who is responsible for installing these modules for me.

        I was researching other user agent modules, but HTML::ParseBrowser thinks that mostly everything is Netscape (when it's clearly Firefox) and HTTP::BrowserDetect thinks that the only IE browser ppl are using is version 4.0 (and as someone said: No offence to that module's writer, but "Is this IE? Yay! Is this 7? Yay" is a bass-ackwards approach to how to detect useragents.)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://872025]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2014-08-02 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (54 votes), past polls