On Fri, 26 Oct 2001, David Gilden wrote: > As an exercise I have two files, a library file and a main > file. If I try to 'use strict' my script won't run.
And it runs with 'use strict'? What errors do you get when you turn on the strict pragma? > # library file dbi-lib.pl > > my $user_name = "******"; > my $user_password = "****"; > my $sql_server = "sql.******.com"; > > > sub initialize_dbi{ > use DBI; > $drh = DBI->install_driver( 'mysql' ); > $dbh = DBI->connect("DBI:mysql:$user_name:$sql_server", $user_name, >$user_password); > die "Cannot connect: $DBI::errstr\n" unless $dbh; > } > > sub run_statement{ > $stmt = "$_[0]"; > $sth = $dbh->prepare($stmt); > $sth->execute; > } This is very questionable code here. You have 'use DBI' in one sub, but not in the second, yet in the second sub, you are not only using a reference from the first sub, you are trying to invoke a method of that reference, which is a database handle object, which is defined in the DBI.pm file. Not only that, under the strict pragma, it will want you to declare your variables with 'my', which will certainly make your library completely unusable. Take a look at the perlmod documentation and look at how to properly build external modules for use in a script. Building '.pl' libraries like this have been superseded by modules and should be pulled in with 'use <Module>;', where <Module> corresponds to a file <Module>.pm. -- Brett http://www.chapelperilous.net/ ------------------------------------------------------------------------ Unix: Some say the learning curve is steep, but you only have to climb it once. -- Karl Lehenbauer -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]