[Brisbane-pm] Messing with Modules
Martin Jacobs
martin_jacobs at optusnet.com.au
Thu Mar 15 23:02:43 PDT 2007
Hi folks,
Here I am again. This time I want to my main program (PERRMOSS) to
execute a block of code in a separate folder (the reason is to give
users a choice in doing a particular calculation).
What I did was straight out of 'Programming Perl', and it kind-of-
works, though probably not as intended.
The block of code is in a file in a sub-folder as follows
input/Simple_Billycan_2_Stage.pm
And it is called in PERRMOSS at line 369 as follows;
use input::Simple_Billycan_2_Stage;
The reason that it is not at the top, after #!/usr/local/bin/perl ,
is that PERRMOSS will not know which module to call until line 369.
Simple_Billycan_2_Stage.pm includes the following (this is not the
final product, by the way);
package Simple_Billycan_2_Stage;
require Exporter;
our @ISA = qw(Exporter);
our @Export = qw(camel);
our @Export_OK = qw(weight);
our $version = 1.00;
sub camel {print "One-hump dromedary\n"}
$weight = 1024;
1;
I understand that 'Exporter' should make 'camel' visible to PERRMOSS.
When I include the line...
Simple_Billycan_2_Stage::camel ();
It works as intended by printing One-hump dromedary to screen.
However, when I include the line...
camel();
I get the error message
Undefined subroutine &main::camel called at perrmoss.pl line 370,
<RF> line 21.
Should I just be able to call 'camel' by camel(); ? Maybe I need to
include the full 'path', though that seems rather messy.
What I am looking for is a way to reference a block of code that is
outside the main program. I understand that modules are the way to
go, but if there is a simpler way to do it, I would be glad to know
about it.
Again, thanks for your help in advance.
Regards,
Martin
Visit my website...
http://web.mac.com/martin_jacobs1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/brisbane-pm/attachments/20070316/80b30515/attachment.html
More information about the Brisbane-pm
mailing list