Yeah this will sure do the trick but just in case you need another option to
do the same , "require" is also there to the rescue.
Just put all the functions you require in a separate .pl file.
The following solution can also be implemented as :
#################################
# Sample.pl
sub InsertSpaces{
my @text = split //,$_[0]; #get characters of function parameter
return join(' ',@text); #return string made of chars w/spaces between
}
1; # required so that file can be correctly included in another script
#- gives a 'true' response when loaded
#################################
#################################
# RequireSample.pl
use strict;
use warnings;
require 'C:\WINNT\Profiles\athind\Desktop\Sample.pl'; #location of the perl
file acting as a repository of all the functions
my $text = InsertSpaces("Hello World!");
print $text;
#################################
This prints "H e l l o W o r l d !" too.
Take your pick :)
Thanks
Aman
-----Original Message-----
From: Timothy Johnson [mailto:tjohnson@;sandisk.com]
Sent: Wednesday, November 06, 2002 9:17 AM
To: 'Johnstone, Colin'; '[EMAIL PROTECTED]'
Subject: RE: Include files in PERL
I think 'use' is what you're looking for. But just in case,
perldoc -f require
perldoc -f use
perldoc perlmod
On the last one, I would recommend reading the first section and then
skipping down to the "Perl Modules" section. Then you can go back over the
whole thing. Just to give you a taste of how modules work, here's a sample
...pm file. Don't forget the 1 at the end.
#################################
# Sample.pm
package Tim::Sample; #assumes the file is at .../site/lib/Tim/
sub InsertSpaces{
my @text = split //,$_[0]; #get characters of function parameter
return join(' ',@text); #return string made of chars w/spaces between
}
1
#################################
#################################
# Sample.pl
use strict;
use warnings;
use Tim::Sample;
my $text = Tim::Sample::InsertSpaces("Hello World!");
print $text;
#################################
This prints "H e l l o W o r l d !".
-----Original Message-----
From: Johnstone, Colin [mailto:Colin.Johnstone@;det.nsw.edu.au]
Sent: Tuesday, November 05, 2002 7:17 PM
To: '[EMAIL PROTECTED]'
Subject: Include files in PERL
Gidday from downunder,
When writing PHP if I want to an include I type include("filename.php");
Is there a similar command in PERL, does require do the job? In my mailing
list application I re-use numerous functions and would like to pop these in
a function library and include them on every page.
Colin Johnstone
Website Project Officer
NSW Department of Education and Training
--
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]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]