Hello David, Saturday, October 27, 2001, David Gilden <[EMAIL PROTECTED]> wrote:
DG> As an exercise I have two files, a library file and a main DG> file. If I try to 'use strict' my script won't run. DG> What do I have to change so that things will work correctly with DG> out clobbering any of my $vars? DG> Thanks and have a good weekend, DG> Dave G. DG> ----- DG> # library file dbi-lib.pl DG> my $user_name = "******"; DG> my $user_password = "****"; DG> my $sql_server = "sql.******.com"; DG> sub initialize_dbi{ DG> use DBI; DG> $drh = DBI->install_driver( 'mysql' ); DG> $dbh = DBI->connect("DBI:mysql:$user_name:$sql_server", $user_name, $user_password); DG> die "Cannot connect: $DBI::errstr\n" unless $dbh; DG> } DG> sub run_statement{ DG> $stmt = "$_[0]"; DG> $sth = $dbh->prepare($stmt); DG> $sth->execute; DG> } DG> 1; DG> # end dbi-lib.pl DG> ------------------ DG> #!/usr/bin/perl -w DG> # Main PERL file DG> use CGI qw/:standard/; DG> use CGI::Carp qw(fatalsToBrowser); DG> require "dbi-lib.pl"; DG> # use strict; DG> my ($d,$s,$time,$week_day, @data); DG> # mySQL Stuff follows DG> &initialize_dbi; DG> $s= "select date_format(current_date, '%W'), date_format(current_date, '%M %e, %Y');"; DG> &run_statement($s); DG> my ($day,$date_string) = $sth->fetchrow; DG> # This $sth is in the library (or is it package?) dbi-lib.pl, correct? unfortunatelly, no. you can check this by enable use strict and then run C:\TMP>perl -c a.pl [Sat Oct 27 01:14:05 2001] a.pl: Global symbol "$sth" requires explicit package name at a.pl line 21. [Sat Oct 27 01:14:05 2001] a.pl: Global symbol "$current_date" requires explicit package name at a.pl line 32. read perldoc perlmod for more information. by the way, don ot use '&' to call function; it' not neccessary. take a look at perldoc perlsub Best wishes, Maxim mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]