Re: A question about modules

2005-12-17 Thread vishal malik
I see. That's fine then. I didn't know that you were using the package 
name as a prefix to the subroutine name (DBConn::). In that case you 
don't need to use the Exporter. You only need it if you want to use the 
the subroutines as if they were in the current package (for example, 
db1(), and not DBConn::db1()).


Vishal


Robert wrote:


I simply use:

my $dbh = DBConn::db1();

It does the right connection (i.e. subroutine) from the DBConn package and I 
didn't use Exporter. I should also mention that DBConn is in the same folder 
and the calling script so maybe that makes a difference.


I am probably going to go back and do a proper module of it so I can get in 
the "habit" of doing so.


Robert

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
 

It is okay to do something like that. However, you should not use the 
package
declaration on the top. If you do that, you will have to use the Exporter 
module

to export your subroutine names to your script when you say "use DBConn;"

Quoting Robert <[EMAIL PROTECTED]>:

   


I have broken out my DB connection calls into a small module. It isn't
anything fancy so it is basically:

package DBConn

use strict;
use warnings;

sub { # connection info for db1 }

sub { # connection info for db2 }

sub { # connection info for db3 }

1;

The question is do I go through the formal process of creating a module 
for

everything (I use Module::Starter) or is it okay to do something like the
above for very small modules?

Robert




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


 





This mail sent through www.mywaterloo.ca 
   





 


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



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




Re: A question about modules

2005-12-17 Thread Shawn Corey

Robert wrote:

I simply use:

my $dbh = DBConn::db1();

It does the right connection (i.e. subroutine) from the DBConn package and I 
didn't use Exporter. I should also mention that DBConn is in the same folder 
and the calling script so maybe that makes a difference.


No, it doesn't. You can mix packages in any manner you like throughout 
your modules. Whether you should ...




I am probably going to go back and do a proper module of it so I can get in 
the "habit" of doing so.


If you want to make a proper module out of it, separate it into three, 
one for each connection. Then add (to each) a close connection 
subroutine, a commit, and a rollback. Change the names so that they are 
more descriptive of the data.


Always write your code as though you won't see it for 25 years and then 
have to change it yesterday.



--

Just my 0.0002 million dollars worth,
   --- Shawn

"Probability is now one. Any problems that are left are your own."
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

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




Re: A question about modules

2005-12-16 Thread Robert
I simply use:

my $dbh = DBConn::db1();

It does the right connection (i.e. subroutine) from the DBConn package and I 
didn't use Exporter. I should also mention that DBConn is in the same folder 
and the calling script so maybe that makes a difference.

I am probably going to go back and do a proper module of it so I can get in 
the "habit" of doing so.

Robert

<[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> It is okay to do something like that. However, you should not use the 
> package
> declaration on the top. If you do that, you will have to use the Exporter 
> module
> to export your subroutine names to your script when you say "use DBConn;"
>
> Quoting Robert <[EMAIL PROTECTED]>:
>
>> I have broken out my DB connection calls into a small module. It isn't
>> anything fancy so it is basically:
>>
>> package DBConn
>>
>> use strict;
>> use warnings;
>>
>> sub { # connection info for db1 }
>>
>> sub { # connection info for db2 }
>>
>> sub { # connection info for db3 }
>>
>> 1;
>>
>> The question is do I go through the formal process of creating a module 
>> for
>> everything (I use Module::Starter) or is it okay to do something like the
>> above for very small modules?
>>
>> Robert
>>
>>
>>
>>
>> -- 
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>  
>>
>>
>
>
>
>
> 
> This mail sent through www.mywaterloo.ca 



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




Re: A question about modules

2005-12-16 Thread vmalik
It is okay to do something like that. However, you should not use the package
declaration on the top. If you do that, you will have to use the Exporter module
to export your subroutine names to your script when you say "use DBConn;"

Quoting Robert <[EMAIL PROTECTED]>:

> I have broken out my DB connection calls into a small module. It isn't 
> anything fancy so it is basically:
> 
> package DBConn
> 
> use strict;
> use warnings;
> 
> sub { # connection info for db1 }
> 
> sub { # connection info for db2 }
> 
> sub { # connection info for db3 }
> 
> 1;
> 
> The question is do I go through the formal process of creating a module for 
> everything (I use Module::Starter) or is it okay to do something like the 
> above for very small modules?
> 
> Robert
> 
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
> 





This mail sent through www.mywaterloo.ca

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




A question about modules

2005-12-15 Thread Robert
I have broken out my DB connection calls into a small module. It isn't 
anything fancy so it is basically:

package DBConn

use strict;
use warnings;

sub { # connection info for db1 }

sub { # connection info for db2 }

sub { # connection info for db3 }

1;

The question is do I go through the formal process of creating a module for 
everything (I use Module::Starter) or is it okay to do something like the 
above for very small modules?

Robert




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