baxy77bax has asked for the wisdom of the Perl Monks concerning the following question:
i'm having some trouble with writing a module. i'm working under win32 and i would like to create a module. actually, just pass some subroutines into a module for organizing purposes. example:
as i tried to show i have 2 scripts *.pl and *.pm and from Test.pl i would like to call a sub NZD which is situated in NZD.pm, that is in a ./Nzd directory. and obviously i don't know how to do it. message i'm getting is that i didn't define the NZD sub"Test.pl" #use lib "./Nzd/"; ->not sure if this should be here #push @INC, "./Nzd/"; ->not sure if this should be here use strict; use warnings; use Nzd::NZD; #Nzd is a directory containing NZD.pm my ($x,$y)= (8,36); my $t=NZD($x,$y); my $c=$x/$t; my $g=$y/$t; print "\nc= $c, g= $g"; ------------------------------------ "NZD.pm" package Nzd::NZD; use strict; sub NZD { my ($x, $b) = @_; if ($x > $b){ ($x,$b) = ($b,$x); } while ($x) { ($x, $b) = ($b % $x, $x); } return $b; } 1;
"Undefined subroutine &main::NZD called at Test.pl line 10."
where is the problem ?
i'm doing wrong...
thanks for all your help
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to write a module
by toolic (Bishop) on Jun 13, 2008 at 17:29 UTC | |
by baxy77bax (Deacon) on Jun 13, 2008 at 17:54 UTC | |
by pc88mxer (Vicar) on Jun 13, 2008 at 19:11 UTC | |
by toolic (Bishop) on Jun 13, 2008 at 19:21 UTC | |
|
Re: how to write a module
by pc88mxer (Vicar) on Jun 13, 2008 at 17:24 UTC | |
|
Re: how to write a module
by sasdrtx (Friar) on Jun 13, 2008 at 17:26 UTC | |
|
Re: how to write a module
by Zen (Deacon) on Jun 13, 2008 at 18:32 UTC |