RE: Evaluated "require $database" not found.

From: Paul Boutros (Paul.Boutros_at_utoronto.ca)
Date: 12/27/04


To: "Ron Wingfield" <rtwingfield@archaxis.net>, <dbi-users@perl.org>
Date: Sun, 26 Dec 2004 23:17:13 -0500

If I understand correctly, you're trying to decide at run-time what module
to include. I don't think that's possible. For example, the following
code:

use strict;
my $val = 'DBI';
require $val;

fails for me on every system I've tried with a:
Can't locate DBI in @INC

So I think you either have to load all modules that you might use, or
instead create a single module with all the connect information you'd need.

> -----Original Message-----
> From: Ron Wingfield [mailto:rtwingfield@archaxis.net]
> Sent: Sunday, December 26, 2004 11:13 PM
> To: Ron Wingfield; dbi-users@perl.org
> Subject: Evaluated "require $database" not found.
>
>
> Continuing to experiment with the evaluation of the "require
> $database" scenario, I've learned this:
> use strict;
> use CGI;
> use Perl_API_Utils; # installed in /www/cgi-bin/perl
> use DBI;
> use lib qw(/usr/home/rtwingfield/bin /www/cgi-bin/perl);
> $cgi = new CGI;
> .
> .
> .
> print # BE AWARE of the SCOPE of "print block" instructions!
> $cgi->header(),
> $cgi->start_html(-title=>$title, -bgcolor=>'cyan'),
> $cgi->start_form(-action=>'contacts_02.pl', -method=>'GET') ; #
> end-print
>
> eval {require $database;};
> if($@){print qq($@<br>);} # Print message if database not found.
> Note that the eval block has to be enclosed by "curly" braces,
> i.e., { }, NOT double-quotes, i.e., " require whatever ". Also,
> I'm assuming that the CGI module only outputs html code within
> the scope of the start_ and end_html( ) function calls;
> otherwise, whatever is "printed" will not be included in the html
> package. (This can be very frustrating for a nubee to learn.)
> In other words, anything to be marked-up and included in the html
> output must be enclosed within the block of code that is
> delimited by the start_ and end_html( ) function calls. (This
> makes perfect sense, . . .now that I understand it. Also, the
> nuance of the scope of a "print block" delimited with a single
> (and sometimes very difficult to find when lost) closing
> semi-colon is a good one to understand!)
>
> Regardless, the "finding" of the database is still failing. At
> least, I'm now able to read this message:
>
> Can't locate cookbook in @INC (@INC contains:
> /usr/home/rtwingfield/bin /www/cgi-bin/perl
> /usr/local/lib/perl5/site_perl/5.8.5/mach
> /usr/local/lib/perl5/site_perl/5.8.5
> /usr/local/lib/perl5/site_perl /usr/local/lib/perl5/5.8.5/BSDPAN
> /usr/local/lib/perl5/5.8.5/mach /usr/local/lib/perl5/5.8.5 .) at
> contacts_01.pl line 36.
>
> . . .as a result of the print instruction per the previous
> example of code. I'm still mystified as to why the database
> cannot be found. Obviously, the connect instructions are not
> going to be successful if this problem is not first resolved.
> Any suggestions?
>
> OTTF,
> Ron Wingfield
>
> FreeBSD 4.8 -- Apache http 2.0.28 -- MySQL client/server 4.1.7
> Perl 5.8.5 -- p5-DBD-mysql-2.9004 driver -- p5-DBI-1.46
>
> ------------------------------------------------------------------
> --------------
>
>
> ----- Original Message -----
> From: Ron Wingfield
> To: dbi-users@perl.org
> Sent: Sunday, December 26, 2004 8:32 PM
> Subject: selectrow_array functions seems to die???
>
>
> Here's another example of a cut of code that doesn't perform as
> expected. It's as if the selectrow_array() function is dying, as
> in (to) die.
>
> if (! database_exists($database)) {
> print qq(<b>Database $database </b>does not exist.<br>);
> }
>
> # Executing the "return" results in no display'able html code.
> sub database_exists {
> my ($dbh, $database) = @_;
> $database =~ s/([%_])/\\$1/g; # escape any special characters
> $dbh->{PrintError}=0;
> $dbh->{RaiseError}=0;
> return ($dbh->selectrow_array("SHOW DATABASES LIKE
> '$database'"));
> }
>
> I put in the "PrintError" and "RaiseError" instructions as an
> afterthought. I always prefer to trap all signals, interrupts,
> etc. and handle them myself; regardless, what is the
> selectrow_array() function doing that is killing the generation
> of html code?
>
> OTTF,
> Ron Wingfield
>
> FreeBSD 4.8 -- Apache http 2.0.28 -- MySQL client/server 4.1.7
> Perl 5.8.5 -- p5-DBD-mysql-2.9004 driver -- p5-DBI-1.46
>
>
> ------------------------------------------------------------------
> --------------
>



Relevant Pages

  • Re: Evaluated "require $database" not found.
    ... To: Ron Wingfield; dbi-users@perl.org ... > use strict; ... > I'm assuming that the CGI module only outputs html code within ... > OTTF, ...
    (perl.dbi.users)
  • Re: Perl script doesnt behave well
    ... use DBI; ... use strict; ... It is best to declare variables at their point of first use, ... scope is necessary, as for $VALUE-A and $VALUE-B, for which see below. ...
    (perl.beginners)
  • Re: Insert Log file into oracle table
    ... so I've created a CLOB field and my code is now: ... use strict; ... use DBI; ... at a time and pull out specific information. ...
    (comp.lang.perl.misc)
  • Re: use of end
    ... and the DBI. ... use strict; ... use warnings; ... cowens@amans:~$ perl t.pl ...
    (perl.beginners)
  • Re: Oracle DBI
    ... >I'm a starter with this subject. ... >my script is: ... >use strict; ... >use DBI; ...
    (perl.beginners)