clo1
asked on
How to create my own module??
I have a bit confuse on the procedure for making my own module. I know I have to use the command h2xs -x -n, but how do I do, I am totally lost !! I want to add this procedure to my module called MyModules
------------------
sub logistic{
my ($xstart, $mv, $N);
my @x;
$x[0] = $xstart;
for (my $i=0; $i<$N; $i++){
$x[$i+1] = $mv * $x[$i] * (1-$x[$i]);
}
return @x;
}
THANKS !
------------------
sub logistic{
my ($xstart, $mv, $N);
my @x;
$x[0] = $xstart;
for (my $i=0; $i<$N; $i++){
$x[$i+1] = $mv * $x[$i] * (1-$x[$i]);
}
return @x;
}
THANKS !
ASKER
Can you also tell me more detaily? Like what should I save the file as. And something like that !
Let's say perl -e 'for (@INC) { printf "%d %s\n", $i++, $_ ;}' tells us this:
0 /usr/lib/perl5/5.005/i386- linux
1 /usr/lib/perl5/5.005
2 /usr/local/lib/site_perl/i 386-linux
3 /usr/local/lib/site_perl
4 /usr/lib/perl5
5 .
Think of MYDIR::MYMODULES as ./MYDIR/MYMODULES.
Put it in one of these directories. Note: there are ways to specify alternative directories, but that is another story.
So you could put it in ...
/usr/local/lib/site_perl/i 386-linux/ MYDIR/MYMO DULES
MYMODULES is the file which has the code in it. It's that simple! Put the code I gave you, and add other functions if you want to like @EXPORT = qw(logistic anotherfunction); where anotherfunction is another function you wrote.
There are other things you can do with @EXPORT, but I am keeping to the basics so that you can understand what modules are about in an easy way .. ofcourse that is the whole point, Perl is suppose to make hard things easier :)
0 /usr/lib/perl5/5.005/i386-
1 /usr/lib/perl5/5.005
2 /usr/local/lib/site_perl/i
3 /usr/local/lib/site_perl
4 /usr/lib/perl5
5 .
Think of MYDIR::MYMODULES as ./MYDIR/MYMODULES.
Put it in one of these directories. Note: there are ways to specify alternative directories, but that is another story.
So you could put it in ...
/usr/local/lib/site_perl/i
MYMODULES is the file which has the code in it. It's that simple! Put the code I gave you, and add other functions if you want to like @EXPORT = qw(logistic anotherfunction); where anotherfunction is another function you wrote.
There are other things you can do with @EXPORT, but I am keeping to the basics so that you can understand what modules are about in an easy way .. ofcourse that is the whole point, Perl is suppose to make hard things easier :)
ASKER
Thanks for your detail instruction. One thing I forgot to tell is I am using ActivePerl build 522 instead of Unix one. Also, if I really want to use h2xs command(because I learn it from my professor), how do I do?
P.s. I have tried the perl -e....command that you gave me, and maybe it doesn't work in the ActivePerl. So I stopped trying.
Hey, post it as an answer pal, and I will give an A to you, cause I am appreciate about your effort. Not only this question, I mean all of the perl question I have asked. Thanks again !!
P.s. I have tried the perl -e....command that you gave me, and maybe it doesn't work in the ActivePerl. So I stopped trying.
Hey, post it as an answer pal, and I will give an A to you, cause I am appreciate about your effort. Not only this question, I mean all of the perl question I have asked. Thanks again !!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Adjusted points to 100
package MYDIR::MYMODULES;
use vars qw(@ISA @EXPORT);
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(logistic);
sub logistic{
my ($xstart, $mv, $N);
my @x;
$x[0] = $xstart;
for (my $i=0; $i<$N; $i++){
$x[$i+1] = $mv * $x[$i] * (1-$x[$i]);
}
return @x;
}
1;