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
In reply to how to write a module by baxy77bax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |