Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Need to turn off prints from module

by kcott (Chancellor)
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

Replies are listed 'Best First'.
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 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);


      $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
        gives me a warning
        Version string '20101026Firefox.0' contains invalid data; ignoring: '20101026Firefox.0' at /usr/local/share/perl/5.8.8/Parse/HTTP/ 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://872025]
and God said, "Let Newton be!"...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2018-04-19 21:56 GMT
Find Nodes?
    Voting Booth?