Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

ignoring errors

by Anonymous Monk
on Mar 07, 2009 at 06:03 UTC ( #749015=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I know this is dumb, but my programming, which has like over 45k lines of code contains a TON of useless void errors. That error is useless to me, so is there a way WITH the -w flag on so I can catch major errors in USE CGI::Carp qw(fatalsToBrowser) to not fill the error log with the useless void context errors?

In other words, I want the -w flag on.
I do not want the error logs to fill up with the useless void errors.

Any help would be greatly appreciated.
Thank you,

Replies are listed 'Best First'.
Re: ignoring errors
by GrandFather (Sage) on Mar 07, 2009 at 06:19 UTC

    void errors generally indicate either useless or inappropriate code. It may be you get a ton of them because one line is executed often, or because there is a recurrent bad coding practise. In either case it would be better to understand and fix the code rather than silence the warning.

    You may like to show us samples of the lines that generate the warning so we can advise on the best solution.

    True laziness is hard work
Re: ignoring errors
by CountZero (Bishop) on Mar 07, 2009 at 07:42 UTC
    I do not want the error logs to fill up with the useless void errors.
    They are not errors, they are warnings and as such they will not kill your program but indicate that something may be wrong. Far better to check that indeed it is harmless or not and then either switch off the warnings or repair it.

    Another way to "solve" this problem is to write a script that filters out all these "useless use of ..." warnings, but I would consider that cheating.


    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: ignoring errors
by gnosti (Hermit) on Mar 07, 2009 at 08:21 UTC
    Since you write that you've already determined that the 'void' warnings are spurious, all that is left is to disable them.

    use warnings; no warnings qw(void);
Re: ignoring errors
by JavaFan (Canon) on Mar 07, 2009 at 10:27 UTC
    -w turns on all warnings, globally. To be specific which warnings you want you have to use 'use warnings'. 'use warnings;' also turns on all warnings (in the current scope, so if you place it on top of the file, for the entire file), but then allows you to turn off specific warnings. So, in your case, something like the following would be appropriate:
    use strict; use warnings; no warnings 'void';
    Or you may turn off the warning in a narrower scope (which is what I would do after I had decided the warning can be ignored).
Re: ignoring errors
by Anonymous Monk on Mar 07, 2009 at 07:13 UTC
      Actually, maybe with $SIG{__WARN__}
Re: ignoring errors
by Anonymous Monk on Mar 08, 2009 at 11:16 UTC
    One of the output errors is:
    Sun Mar 8 04:09:33 2009 index3.cgi: DBI::db=HASH(0x11723900)->disconnect invalidates 2 active statement handles (either destroy statement handles or call finish on them before disconnecting) at /usr/lib/perl5/site_perl/5.8.8/Apache/Session/Lock/ line 90, <DATA> line 842.

    (Yes I use Apache::Session::MySQL on every page)
    I always call finish on all connections made with prepare(), and I always call disconnect() before I ever exit the program, even when I redirect the window, so I do not know why that message is in every page load...

    Also, when I take out -w and just run:
    the page gets an internal error, even though the output is built with CGI print header()...
    so I did this:
    #!/usr/bin/perl -a
    which I cannot find means anything anywhere and then everything works just fine, fast and error free, including in shell with no errors.

    Any advice?
      d just run: #!/usr/bin/perl the page gets an internal error, even though the output is built with
      See CGI Help Guide "3. Is the shebang line pointed at the Perl interpreter?"

      #!/usr/bin/perl -- is easier than messing with dos2unix ... to fix #!/usr/bin/perl^M

      Re: the page gets an internal error

      What is the error that appears in your server error log?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://749015]
Approved by GrandFather
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2018-05-22 18:36 GMT
Find Nodes?
    Voting Booth?