RE: Divide Perl script

2003-02-27 Thread Chris Rogers
Just create a separate file to hold your library routines.  You may name
the file anything you like.  Be sure to put the line:

#!/usr/bin/perl

at the top of the file (changing it to match where your version of perl is
installed).  I also put a:

1;

on the next line to keep perl from bombing out(this may not be necessary for
you but it was for me).  Then just put all your subroutines in the new file:

sub MySub
{
...(code here)
}
sub MySub2{
{
...(code here)
}

The last step is to put a require statement in your perl program so that
it knows where to find the library or subroutines.  This line looks like
this:

require '/var/www/cgi-bin/lib/filename';

Of course you will need to change the above line to match your directory
structure and filename.  That's all there is to it.  Hope this helps.

Chris


-Original Message-
From: Shishir K. Singh [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 27, 2003 4:47 PM
To: [EMAIL PROTECTED]
Subject: Divide Perl script


Hello, 

How can I divide my perl program in different files(in other words..move the
sub routines in different files ) and then do an include in the mail perl
file. The reason why I want to do this is because my main program is growing
day by day and it's becoming difficult to navigate through it. Is there any
alternate method to do this?

TIA
Shishir

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

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



RE: Divide Perl script

2003-02-27 Thread Shishir K. Singh
Thanks to everyone, it works. 

-Original Message-
From: Chris Rogers [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 27, 2003 4:58 PM
To: Shishir K. Singh; [EMAIL PROTECTED]
Subject: RE: Divide Perl script


Just create a separate file to hold your library routines.  You may name
the file anything you like.  Be sure to put the line:

#!/usr/bin/perl

at the top of the file (changing it to match where your version of perl is
installed).  I also put a:

1;

on the next line to keep perl from bombing out(this may not be necessary for
you but it was for me).  Then just put all your subroutines in the new file:

sub MySub
{
...(code here)
}
sub MySub2{
{
...(code here)
}

The last step is to put a require statement in your perl program so that
it knows where to find the library or subroutines.  This line looks like
this:

require '/var/www/cgi-bin/lib/filename';

Of course you will need to change the above line to match your directory
structure and filename.  That's all there is to it.  Hope this helps.

Chris


-Original Message-
From: Shishir K. Singh [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 27, 2003 4:47 PM
To: [EMAIL PROTECTED]
Subject: Divide Perl script


Hello, 

How can I divide my perl program in different files(in other words..move the
sub routines in different files ) and then do an include in the mail perl
file. The reason why I want to do this is because my main program is growing
day by day and it's becoming difficult to navigate through it. Is there any
alternate method to do this?

TIA
Shishir

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

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



Re: Divide Perl script

2003-02-27 Thread Harry Putnam
Shishir K. Singh [EMAIL PROTECTED] writes:

 Hello, 

 How can I divide my perl program in different files(in other
 words..move the sub routines in different files ) and then do an
 include in the mail perl file. The reason why I want to do this is
 because my main program is growing day by day and it's becoming
 difficult to navigate through it. Is there any alternate method to
 do this?

One of the easier ways is to put all the subroutines into a file with
a .pm extension

mysubs.pm   and put it somewhere inside @INC

Then in your scripts put:

 use mysubs;

(note the extension pm is left out in the `use') but the file name
must have it.

Find out where @INC is with `perl -V'

If you have permissions put it somewhere like:

 /usr/lib/perl5/site_perl

Other wise investigate  `require' and
use lib

Something like 
`use lib /path/to/dir;'
Then put mysubs.pm in /path/to/dir 


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



Re: Divide Perl script

2003-02-27 Thread R. Joseph Newton
Chris Rogers wrote:

 Just create a separate file to hold your library routines.  You may name
 the file anything you like.  Be sure to put the line:


Good advice.  It is a good idea to use a .pm extension, and to have a package name 
identical to the base name:

file: rjnWeb.pm
in script:
package rjnWeb;

some Perl installations are very picky about packages being labeled.


 #!/usr/bin/perl

 at the top of the file (changing it to match where your version of perl is
 installed).  I also put a:

 1;

 on the next line [RJN--see comment below] to keep perl from bombing out(this may not 
 be necessary for
 you but it was for me).  Then just put all your subroutines in the new file:

Putting the true return value immediately after the headers and the package label 
command will work, because encapsulated code is not read in the main body of the 
script, thereofre the last line of script comes before the function definitions.  It 
could make it harder for others when you share your code though, as the convention is 
to put the true return value as the last line of code, like so:
1;
__END__

Also note, that this need not be the number one.  The perl interpreter expects its 
reading of the module to return a true value.  This can be anything other than 0 or 
undef.  For instance:
Geeks rule!;
__END__
would do just as well.

 sub MySub
 {
 ...(code here)
 }
 sub MySub2{
 {
 ...(code here)
 }

 The last step is to put a require statement in your perl program so that
 it knows where to find the library or subroutines.  This line looks like

Read around in the archives.  You will find numerous explanations of why the use 
function generally works better.  It will call the require function anyway, as well as 
providing a greater transparency.

Joseph


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