-----Original Message-----
>From: Umar Draz <[EMAIL PROTECTED]>
>Sent: Mar 14, 2007 6:37 PM
>To: beginners@perl.org
>Subject: how to use require??
>
>HI dear members! I have a file called dbcon.pl into include directory.
>
>#!/usr/local/bin/perl
>
>use DBI;
>
># Database Username, Password and Driver settings
>my $user="konsole";
>my $pass="send";
>my $host="localhost";
>my $driver="mysql";
>my $db="treat";
>my $tnt="xyz";
>
># Connect Database
>my $dsn = "DBI:$driver:database=$db;host=$host";
>my $dbh = DBI->connect($dsn, $user, $pass);
>
>Now I have created a another file login.pl there i include dbcon.pl using 
>require.
>

Hello,

You have required the file correctly but you can't export any variables in this 
file to the main script.Because all the variables in this file are not package 
variables,since you declare them using "my".For exporting successfully,you may 
need to declare them as Perl's package variables.

Here if you only need the $dbh to be exported to the main script,you can write:

our $dbh = $DBI->connect($dsn,$user,$pass);  # replace "my" with "our"

I think this could work.

For more info about perl's variable scope,please see:
http://perl.plover.com/FAQs/Namespaces.html.en

Hope this useful.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to