> Hello,
> 
> I have a main prog and some subs in different files.
> At runtime I use "require �pathtofile/�;" to include these files to the 
> main prog as subs. In the main prog I�m using the modul HandySQL3 with a 
> databasehandle let�s say
> 
> /snip/
> ##main prog ##

use strict;
use warnings; 

> 
> require �./sub.pl�;
> 
> use HandySQL3;
> my $dbh=HandySQL3->new("$sqluser","$sqlpass","$database","$sqlhost");

Your 'dbh' is lexically scoped, which means it goes out of view at the
end of the file, therefore it will not be available for use in your
subroutine.  Using either 'our' or 'use vars' will fix the symptom, see
below for more about the problem...

perldoc -f our
perldoc vars

> $dbh->configure({
>       'compress=0',
>       'timeout=45',
>       'exceptions=1'
>           });
> /snip/
> 
> The sub.pl:
> 
> /snip/
> sub test{
>      eval{
>      $dbh->sql_connect();
>      };
> }     

In your sub you are using $dbh as a global, don't do that.  You should
either pass everything you will need in your sub into your sub as
arguments, or consider switching the sub into a method of an object and
storing the data structure as the object's attributes.  Assuming you
don't want to do the latter right away since it is a paradigm shift, 

sub test {
  my ($dbh, ...) = @_;

  # don't forget to test for existence and validity of arguments
  eval {
      $dbh->sql_connect;
  }
}

Then your call to the sub becomes:

test($dbh);

> 
> Why does the transfer oft $dbh not work?
> Can anybody help me, please!
> 

http://perl.plover.com/FAQs/Namespaces.html

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to