Okay, this is bizarre. In one particular program (which uses Class::DBI), when I "use diagnostics", the program fails to compile, complaining that it cannot find "DBI/db.pm". If I "use warnings" instead, the program compiles fine and runs perfectly.

Consider the following code (stripped of all useful statements), which you can use on your system to determine whether you get the same behavior:


mydemo.pl

#!/usr/bin/perl use strict; use diagnostics; # use warnings works use lib "."; use MyTable;

MyTable.pm

package MyTable; use base 'MyDatabase'; 1;

MyDatabase.pm

package MyDatabase; use base 'Class::DBI'; 1;

When I try to run "mydemo.pl" with "use diagnostics", I get a boatload of errors about being unable to load "DBI/db.pm". Here's a few lines from the start:


Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Uncaught exception from user code: Can't locate DBI/db.pm in @INC (@INC contains: . /usr/local/li +b/perl5/5.6.1/sun4- solaris /usr/local/lib/perl5/5.6.1 /usr/local/lib/perl5/site _perl/5.6.1/sun4- solaris /usr/local/lib/perl5/site_perl/5.6.1 /usr/local/lib/ perl5/site_perl/5.6.0/sun4- solaris /usr/local/lib/perl5/site_perl/5.6.0 /usr/local/lib/ perl5/site_perl/5.005/sun4- solaris /usr/local/lib/perl5/site_perl/5.005 /usr/local/lib/ perl5/site_perl) at (eval 6) line 3. eval 'require DBI::db ;' called at /usr/local/lib/perl5/5.6.1/base.pm line 59 base::import('base', 'DBI::db') called at /usr/local/lib/perl5/site_perl/5.6.1/Ima/DBI.pm line 645 Ima::DBI::db::BEGIN() called at DBI/db.pm line 0 eval {...} called at DBI/db.pm line 0 require Ima/DBI.pm called at (eval 5) line 3 eval 'require Ima::DBI ;' called at /usr/local/lib/perl5/5.6.1/base.pm line 59 base::import('base', 'Class::Accessor', 'Class::Data::Inherita +ble', 'Ima ::DBI') called at /usr/local/lib/perl5/site_perl/5.6.1/Class/DBI.pm line 6 Class::DBI::__::Base::BEGIN() called at DBI/db.pm line 0 eval {...} called at DBI/db.pm line 0 require Class/DBI.pm called at (eval 3) line 3 eval 'require Class::DBI ;' called at /usr/local/lib/perl5/5.6.1/base.pm line 59

It goes on and on like that. Just change "diagnostics" to "warnings" and the problems go away (not to mention that, with the actual code in place, the program works).

What kind of weirdness have I stumbled across? Has anyone else seen something like this? (I spent about 5 hours trying to figure out why one program was working while a similar program -- use had the "use diagnostics" line -- was not!) This is Perl 5.6.1 under Sun Solaris 7.

Wally Hartshorn

(Plug: Visit JavaJunkies, PerlMonks for Java)


In reply to Why Does My Class::DBI Program Break Under "use diagnostics" Pragma? by Wally Hartshorn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.